private static AggregationResponse GetAggregation(AggregationRequest aggregationRequest, IDictionary <string, Filter> valueFilters, IndexSearcher searcher, bool sortValues, int?maxValuesCount, ICollection <string> availableFields) { AggregationResponse result = null; if (aggregationRequest != null) { if (valueFilters != null) { var commonFilter = LuceneSearchFilterBuilder.GetFilterRecursive(aggregationRequest.Filter, availableFields); var values = valueFilters.Select(kvp => GetAggregationValue(kvp.Key, kvp.Value, commonFilter, searcher)) .Where(v => v != null); if (sortValues) { values = values .OrderByDescending(v => v.Count) .ThenBy(v => v.Id); } if (maxValuesCount > 0) { values = values.Take(maxValuesCount.Value); } result = new AggregationResponse { Id = aggregationRequest.Id ?? aggregationRequest.FieldName, Values = values.ToArray(), }; } } return(result); }
private static Filter GetFilters(SearchRequest request, ICollection <string> availableFields) { return(LuceneSearchFilterBuilder.GetFilterRecursive(request.Filter, availableFields)); }