Exemple #1
0
        private static AggregationResponse GetRangeAggregation(RangeAggregationRequest rangeAggregationRequest, FacetResults facets)
        {
            AggregationResponse result = null;

            if (rangeAggregationRequest != null)
            {
                var azureFieldName = AzureSearchHelper.ToAzureFieldName(rangeAggregationRequest.FieldName);
                if (!string.IsNullOrEmpty(azureFieldName))
                {
                    var facetResults = facets.ContainsKey(azureFieldName) ? facets[azureFieldName] : null;

                    if (facetResults != null && facetResults.Any())
                    {
                        result = new AggregationResponse
                        {
                            Id     = (rangeAggregationRequest.Id ?? rangeAggregationRequest.FieldName).ToLowerInvariant(),
                            Values = new List <AggregationResponseValue>(),
                        };

                        foreach (var value in rangeAggregationRequest.Values)
                        {
                            var facetResult = GetRangeFacetResult(value, facetResults);
                            AddAggregationValue(result, facetResult, value.Id);
                        }
                    }
                }
            }

            return(result);
        }
        private static AggregationResponse CreateRangeAggregationResponse(RangeAggregationRequest rangeAggregationRequest, IndexSearcher searcher, ICollection <string> availableFields)
        {
            AggregationResponse result = null;

            if (rangeAggregationRequest != null)
            {
                var fieldName    = LuceneSearchHelper.ToLuceneFieldName(rangeAggregationRequest.FieldName);
                var valueFilters = rangeAggregationRequest.Values?.ToDictionary(v => v.Id, v => LuceneSearchFilterBuilder.CreateRangeFilterForValue(fieldName, v.Lower, v.Upper, v.IncludeLower, v.IncludeUpper));

                result = GetAggregation(rangeAggregationRequest, valueFilters, searcher, false, null, availableFields);
            }

            return(result);
        }
        private static string CreateRangeAggregationRequest(RangeAggregationRequest rangeAggregationRequest, IList <Field> availableFields)
        {
            string result = null;

            var availableField = availableFields.Get(rangeAggregationRequest.FieldName);

            if (availableField != null)
            {
                var edgeValues = rangeAggregationRequest.Values
                                 .SelectMany(v => new[] { ConvertToDecimal(v.Lower), ConvertToDecimal(v.Upper) })
                                 .Where(v => v > 0m)
                                 .Distinct()
                                 .OrderBy(v => v)
                                 .Select(v => v.ToString(CultureInfo.InvariantCulture))
                                 .ToArray();

                var values = string.Join("|", edgeValues);

                result = $"{availableField.Name},values:{values}";
            }

            return(result);
        }