Пример #1
0
        private static IList <AggregationResponse> GetAggregations(IReadOnlyDictionary <string, IAggregate> searchResponseAggregations, Domain.Search.SearchRequest request)
        {
            var result = new List <AggregationResponse>();

            if (request?.Aggregations != null && searchResponseAggregations != null)
            {
                foreach (var aggregationRequest in request.Aggregations)
                {
                    var aggregation = new AggregationResponse
                    {
                        Id     = aggregationRequest.Id ?? aggregationRequest.FieldName,
                        Values = new List <AggregationResponseValue>(),
                    };

                    var termAggregationRequest  = aggregationRequest as TermAggregationRequest;
                    var rangeAggregationRequest = aggregationRequest as RangeAggregationRequest;

                    if (termAggregationRequest != null)
                    {
                        AddAggregationValues(aggregation, aggregation.Id, aggregation.Id, searchResponseAggregations);
                    }
                    else if (rangeAggregationRequest?.Values != null)
                    {
                        foreach (var value in rangeAggregationRequest.Values)
                        {
                            var queryValueId    = value.Id;
                            var responseValueId = $"{aggregation.Id}-{queryValueId}";
                            AddAggregationValues(aggregation, responseValueId, queryValueId, searchResponseAggregations);
                        }
                    }

                    if (aggregation.Values.Any())
                    {
                        result.Add(aggregation);
                    }
                }
            }

            return(result);
        }
Пример #2
0
        public static SearchResponse ToSearchResponse(this ISearchResponse <SearchDocument> response, Domain.Search.SearchRequest request, string documentType)
        {
            var result = new SearchResponse
            {
                TotalCount   = response.Total,
                Documents    = response.Hits.Select(ToSearchDocument).ToArray(),
                Aggregations = GetAggregations(response.Aggregations, request)
            };

            return(result);
        }