// // GET: /Search/ public ActionResult Search(string q, int startPaging = 0) { ViewData["resultPageSize"] = resultPageSize; if (string.IsNullOrEmpty(q)) { return this.RedirectToAction("Index"); } else { this.eng = FactoryEngine.GetEngine(); ResultSearchModel model = new ResultSearchModel(); model.query = q; model.start = startPaging; List<DocumentResult> tmpResult = Search(q, model); model.results = tmpResult; if ((model.results.Count - startPaging) > resultPageSize) { ViewData["offSet"] = startPaging + resultPageSize; } else { ViewData["offSet"] = startPaging + (model.results.Count - startPaging); } return View(model); } }
private List<DocumentResult> Search(string query, ResultSearchModel model) { IRepositoryLog repLog = FactoryRepositoryLog.GetRepositoryLog(); engConf = EngineConfiguration.Instance; IEngine eng = FactoryEngine.GetEngine(); DateTime start; TimeSpan timeDif; Stopwatch sw; string smsSearch = "Search".PadRight(15); start = DateTime.Now; sw = Stopwatch.StartNew(); List<DocumentResult> result = eng.Search(query); sw.Stop(); timeDif = sw.Elapsed; Log entry = new Log(); entry.TaskDescription = smsSearch; entry.StartDateTime = start; entry.ExecutionTime = timeDif; entry.LogParameters = new List<string>(); entry.LogParameters.Add("sentence: " + query); entry.LogParameters.Add("totalDocFound: " + result.Count.ToString()); entry.LogParameters.Add("totalDocIndexed: " + eng.TotalDocumentQuantity.ToString()); entry.LogParameters.Add("RankTypeFunction: " + engConf.RankTypeFunction); if (model.start == 0) { repLog.Write(entry); } if (result.Count > 0) { if (model.start == 0) { WriteResultsToDisk(result, query); } foreach (DocumentResult item in result) { string physicalRepositoryPath = EngineConfiguration.Instance.PathFolderRepository; string virtualRepositoryParh = ConfigurationManager.AppSettings["pathVirtualRepository"] as string; string resultPath = item.File.Remove(0, physicalRepositoryPath.Length); resultPath = virtualRepositoryParh + resultPath.Replace("\\", "/"); resultPath = GetEncodedString(resultPath); string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/"; if (String.IsNullOrEmpty(item.Url)) { item.Url = baseUrl+ resultPath; } } } return result; }