Beispiel #1
0
        /// <summary>
        ///     Creates a new list of a <see cref="Facets.SelectedFacet" /> from a <see cref="filter" /> object.
        /// </summary>
        /// <param name="filter">Facet to create the facet predicate from.</param>
        /// <param name="setting">Settings of the facet</param>
        /// <param name="cultureInfo">Culture in which the display names will be returned in</param>
        public IEnumerable <Facets.SelectedFacet> CreateSelectedFacetList(SearchFilter filter, FacetSetting setting,
                                                                          CultureInfo cultureInfo)
        {
            if (filter == null)
            {
                throw new ArgumentNullException(nameof(filter));
            }
            if (setting == null)
            {
                throw new ArgumentNullException(nameof(setting));
            }

            if (!setting.FieldName.Equals(filter.Name, StringComparison.OrdinalIgnoreCase))
            {
                throw new ArgumentException(
                          string.Format("The specified setting is for the facet '{0}', whereas the filter is for the facet '{1}'",
                                        setting.FieldName, filter.Name), nameof(setting));
            }

            if (setting.FacetType != FacetType)
            {
                throw new ArgumentException(
                          string.Format("The facetResult is defined as '{0}' which does not match '{1}'",
                                        setting.FacetType, FacetType), nameof(setting));
            }

            return(new List <Facets.SelectedFacet>
            {
                new Facets.SelectedFacet
                {
                    FieldName = filter.Name,
                    DisplayName = FacetLocalizationProvider.GetFormattedFacetValueTitle(filter.Name, filter.Value, cultureInfo),
                    FacetType = FacetType,
                    IsRemovable = !filter.IsSystem,
                    Value = filter.Value
                }
            });
        }
        protected virtual List <FacetValue> GetFacetValues(Overture.ServiceModel.Search.Facet facetResult, FacetSetting setting,
                                                           IReadOnlyCollection <string> selectedFacetValues, CultureInfo cultureInfo)
        {
            var promotedValues = setting.PromotedValues;

            /*Expected to be already sorted*/
            var facetValues = facetResult.Values
                              .Select(resultFacetValue =>
            {
                var facetValue = new FacetValue
                {
                    Title =
                        FacetLocalizationProvider.GetFormattedFacetValueTitle(facetResult.FieldName,
                                                                              resultFacetValue.Value, cultureInfo),
                    Value        = resultFacetValue.Value,
                    Quantity     = resultFacetValue.Count,
                    IsSelected   = selectedFacetValues.Contains(resultFacetValue.Value),
                    MinimumValue = resultFacetValue.MinimumValue,
                    MaximumValue = resultFacetValue.MaximumValue
                };

                var promotedValueSetting =
                    promotedValues.FirstOrDefault(
                        value => value.Title.Equals(resultFacetValue.Value, StringComparison.OrdinalIgnoreCase));

                if (promotedValueSetting != null)
                {
                    facetValue.IsPromoted          = true;
                    facetValue.PromotionSortWeight = promotedValueSetting.SortWeight;
                }

                return(facetValue);
            })
                              .ToList();

            facetValues = facetValues.OrderByDescending(x => x.IsSelected).ToList();
            return(facetValues);
        }