//API for getting logs public ReturnListWithSearchModel <AppLog, AppLogSearchCriteria> GetAppLogs(AppLogSearchCriteria search) { try { using (var reader = GetNewAppReader().OpenSession <AppLog>()) { LuceneQueryStatistics stats = null; var lst = reader.Query(); lst = lst.CaptureStatistics(s => { stats = s; }); lst = AddFilters(lst, search.SearchTerms); lst = ApplySort(lst, search.SortBy, search.SortAscending, "LongdateAsTicks"); var totalRows = lst.AsQueryable().Count(); search.TotalRowCount = totalRows; var resultList = lst.ApplyPaging(search.Page, search.PageSize).ToList(); search.CurrentRows = resultList.Count; return(new ReturnListWithSearchModel <AppLog, AppLogSearchCriteria>(search, resultList, totalRows)); } } catch (Exception ex) { log.Error(ex, "Error when getting App Log List "); search.TotalRowCount = 0; search.CurrentRows = 0; return(new ReturnListWithSearchModel <AppLog, AppLogSearchCriteria>(search, ex)); } }
private static void AssertComputedQueryEquals(IQueryable <IPackage> query, string expectedQuery) { LuceneQueryStatistics stats = null; var result = query.CaptureStatistics(s => { stats = s; }).ToArray(); Assert.That(stats.Query.ToString(), Is.EqualTo(expectedQuery)); }
public void CountsTotalHits() { LuceneQueryStatistics stats = null; documents.CaptureStatistics(s => { stats = s; }).Skip(1).Take(1).Count(); Assert.That(stats, Is.Not.Null, "stats"); Assert.That(stats.TotalHits, Is.EqualTo(documents.Count())); }
protected override ReturnListWithSearchModel <T, BaseSearchCriteria> GetDistinctColumns <T>(StoredLogType logType, BaseSearchCriteria search, Expression <Func <AppLog, T> > selector, string columnType) { try { using (var reader = GetNewAppReader().OpenSession <AppLog>()) { LuceneQueryStatistics stats = null; var lst = reader.Query().Where(x => x.LogType == (int)logType).Select(selector).Distinct().CaptureStatistics(x => stats = x); var totalRows = lst.AsQueryable().Count(); search.TotalRowCount = totalRows; var resultList = lst.ApplyPaging(search.Page, search.PageSize).Distinct().ToList(); search.CurrentRows = resultList.Count; return(new ReturnListWithSearchModel <T, BaseSearchCriteria>(search, resultList, totalRows)); } } catch (Exception ex) { log.Error(ex, $"Error when getting {columnType} list "); search.TotalRowCount = 0; search.CurrentRows = 0; return(new ReturnListWithSearchModel <T, BaseSearchCriteria>(search, $"Error when getting {columnType} list ", ex)); } }
public dynamic Search( string query = "", bool includePrerelease = false, bool latestOnly = true, int offset = 0, int count = 20, PackageOriginFilter originFilter = PackageOriginFilter.Any, SearchSortField sort = SearchSortField.Score, SearchSortDirection order = SearchSortDirection.Ascending) { var criteria = new SearchCriteria(query) { AllowPrereleaseVersions = includePrerelease, PackageOriginFilter = originFilter, SortField = sort, SortDirection = order }; LuceneQueryStatistics stats = null; List <IPackage> hits; try { var queryable = LuceneRepository.Search(criteria).CaptureStatistics(s => stats = s); if (latestOnly) { queryable = queryable.LatestOnly(includePrerelease); } hits = queryable.Skip(offset).Take(count).ToList(); } catch (InvalidSearchCriteriaException ex) { var message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, message)); } dynamic result = new ExpandoObject(); // criteria result.Query = query; result.IncludePrerelease = includePrerelease; result.TotalHits = stats.TotalHits; result.OriginFilter = originFilter; result.Sort = sort; result.Order = order; // statistics result.Offset = stats.SkippedHits; result.Count = stats.RetrievedDocuments; result.ElapsedPreparationTime = stats.ElapsedPreparationTime; result.ElapsedSearchTime = stats.ElapsedSearchTime; result.ElapsedRetrievalTime = stats.ElapsedRetrievalTime; var chars = stats.Query.ToString().Normalize(NormalizationForm.FormD); result.ComputedQuery = new string(chars.Where(c => c < 0x7f && !char.IsControl(c)).ToArray()); // hits result.Hits = hits; return(result); }