public void PopulateElasticDb() { if (!mysqlDbAccess.Connect()) { Console.WriteLine("Unable to connect to mysql db"); } IEnumerable <VoterInfoComelec> listDbVoters = mysqlDbAccess.IterateAll2(); int i = 0; long currTime = Environment.TickCount; foreach (VoterInfoComelec voter in listDbVoters) { VoterInfo emVoter = MapVoterInfo(voter); //emgr.CreateNewVoter(emVoter); if (i % 10000 == 0) { Console.WriteLine("Written {0} out of 75302673 records to elastic, took {1}", i, Environment.TickCount - currTime); currTime = Environment.TickCount; } i++; } mysqlDbAccess.Disconnect(); }
//[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()); } }