internal static IEnumerable <KeyValuePair <string, Expression <Func <FindDocument, Filter> > > > GetFacets(this ITypeSearch <FindDocument> search, SearchFilter filter, string locale) { ISearchConfiguration config = search.Client.GetConfiguration(); IFieldConfiguration field; int index; if (FindProviderExtensions.IsSimpleFacet(filter) && config.TryGetField(filter.field, locale, out field)) { SimpleValue[] simpleValueArray = filter.Values.SimpleValue; for (index = 0; index < simpleValueArray.Length; ++index) { SimpleValue simpleValue = simpleValueArray[index]; yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, simpleValue.key), UntypedFilterBuilder.GetMatchFilter(field, simpleValue.value))); } simpleValueArray = (SimpleValue[])null; } if (FindProviderExtensions.IsRangeFacet(filter) && config.TryGetField(filter.field, locale, out field)) { RangeValue[] rangeValueArray = filter.Values.RangeValue; for (index = 0; index < rangeValueArray.Length; ++index) { RangeValue rangeValue = rangeValueArray[index]; yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, rangeValue.key), UntypedFilterBuilder.GetRangeFilter(field, rangeValue.lowerbound, rangeValue.upperbound, rangeValue.lowerboundincluded, rangeValue.upperboundincluded))); } rangeValueArray = (RangeValue[])null; } }
internal static IEnumerable <KeyValuePair <string, Expression <Func <FindDocument, Filter> > > > GetPriceFacets(this ITypeSearch <FindDocument> search, SearchFilter filter, Mediachase.Commerce.Currency currency, MarketId marketId) { IFieldConfiguration <double?> field; if (FindProviderExtensions.IsPriceRangeFacet(filter) && search.Client.GetConfiguration().TryGetPriceField(filter.field, currency, marketId, out field)) { foreach (PriceRangeValue priceRangeValue in ((IEnumerable <PriceRangeValue>)filter.Values.PriceRangeValue).Where <PriceRangeValue>((Func <PriceRangeValue, bool>)(prv => string.Equals(prv.currency, (string)currency, StringComparison.OrdinalIgnoreCase)))) { yield return(new KeyValuePair <string, Expression <Func <FindDocument, Filter> > >(FindProviderExtensions.EncodeFacetName(field.Name, priceRangeValue.key), UntypedFilterBuilder.GetRangeFilter((IFieldConfiguration)field, priceRangeValue.lowerbound, priceRangeValue.upperbound, priceRangeValue.lowerboundincluded, priceRangeValue.upperboundincluded))); } } }
private void AddFacetResult(FacetGroup facetGroup, Dictionary <string, FilterFacet> facetsByName, string field, string key, Descriptions descriptions, string locale) { string key1 = FindProviderExtensions.EncodeFacetName(field, key); FilterFacet filterFacet; if (!facetsByName.TryGetValue(key1, out filterFacet) || filterFacet.Count <= 0) { return; } string facetDescription = this.GetFacetDescription(descriptions, locale); Mediachase.Search.Extensions.Facet facet = new Mediachase.Search.Extensions.Facet((ISearchFacetGroup)facetGroup, key, facetDescription, filterFacet.Count); facetGroup.Facets.Add((ISearchFacet)facet); }