Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ElasticManager emgr = new ElasticManager();

            //emgr.CreateIndex();

            //VoterInfo newVoter = new VoterInfo
            //{
            //    Lastname = "Lee",
            //    Firstname = "Kuan Yew",
            //    Maternalname = "Z",
            //    Address = "Singapore",
            //    CivilStatus = "M",
            //    DateOfBirth = DateTime.Parse("1935-01-01"),
            //    Sex = "M",
            //};

            //emgr.CreateNewVoter(newVoter);

            //VoterInfo query = new VoterInfo
            //{

            //};

            //emgr.Query(null);
            //emgr.Query2();
            emgr.Query3("raymond", "", "ong", "");
            //ComelecDbWriter dbWriter = new ComelecDbWriter();
            //dbWriter.PopulateElasticDb();
            //dbWriter.PopulateElasticDbBulk();
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        //[Authorize]
        public ActionResult Index()
        {
            Debug.WriteLine("HashCode: {0}", this.GetHashCode());

            if (Request.IsAjaxRequest())
            {
                // default values
                int    pageNumber = 1;
                string sortBy     = "FirstName";
                string SortOrder  = null;
                string ExactMatch = Request.Params["exactmatch"] != null ? Request.Params["exactmatch"] : "Exact";
                try
                {
                    if (Request.Params["page"] != null)
                    {
                        pageNumber = Convert.ToInt32(Request.Params["page"]);
                    }
                    if (Request.Params["sortBy"] != null)
                    {
                        sortBy = Request.Params["sortBy"];
                    }
                    if (Request.Params["SortOrder"] != null)
                    {
                        SortOrder = Request.Params["SortOrder"];
                    }
                }
                catch (Exception ex)
                {
                    // just swallow exception
                }

#if true
                IEnumerable <models.VoterInfo> sortedVoters = null;
                if (ExactMatch == "Exact")
                {
                    ComelecDbAccessor dbAccess = new ComelecDbAccessor();
                    dbAccess.Connect();
                    //List<VoterInfoComelec> listDbVoters = dbAccess.SearchData(
                    List <VoterInfoComelec> listDbVoters = dbAccess.SearchDataIterator(
                        Request.Params["FirstName"],
                        Request.Params["MaternalName"],
                        Request.Params["LastName"]).ToList();

                    sortedVoters = SortVoters(listDbVoters, sortBy, SortOrder);
                }
                else
                {
                    elastic.ElasticManager emgr = new elastic.ElasticManager();
                    List <ElasticSearchWriter.VoterInfo> elasticResultList = emgr.Query3(
                        Request.Params["FirstName"],
                        Request.Params["MaternalName"],
                        Request.Params["LastName"],
                        Request.Params["Address"]);

                    sortedVoters = SortVotersElastic(elasticResultList, Request.Params["sortBy"], SortOrder);
                }
                var pagedList = sortedVoters.ToPagedList(pageNumber, 10);
                //return PartialView("SearchResult", pagedList);
                return(PartialView("SearchResult", sortedVoters));
#else
                List <VoterInfo>        listDbVoters = GeneratelistDbVoters();
                IEnumerable <VoterInfo> sortedVoters = Sort(listDbVoters, sortBy, SortOrder);
                var pagedList = sortedVoters.ToPagedList(pageNumber, 10);
                return(PartialView("SearchResult", pagedList));
#endif
            }
            else
            {
                return(View());
            }
        }