コード例 #1
0
        /// <summary>
        /// Checks aggregation item values for the equality with the filters, and set <see cref="AggregationItem.IsApplied"/> to those, whose value equal to  on of the filters
        /// </summary>
        /// <param name="searchRequest">Search request</param>
        /// <param name="aggregations">Calculated aggregation results</param>
        public static void SetAppliedAggregations(this SearchRequest searchRequest, Aggregation[] aggregations)
        {
            if (searchRequest == null)
            {
                throw new ArgumentNullException(nameof(searchRequest));
            }
            if (aggregations == null)
            {
                throw new ArgumentNullException(nameof(aggregations));
            }

            foreach (var childFilter in searchRequest.GetChildFilters())
            {
                var aggregationItems = aggregations.Where(x => x.Field.EqualsInvariant(childFilter.GetFieldName()))
                                       .SelectMany(x => x.Items)
                                       .ToArray();

                childFilter.FillIsAppliedForItems(aggregationItems);
            }
        }