Example #1
0
        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;
            }
        }
Example #2
0
        /// <summary>
        /// Adds a single active filter from an ISearchCriteria object to an existing search.
        /// </summary>
        public static ITypeSearch <FindDocument> AddActiveFilter(this ITypeSearch <FindDocument> search, string fieldName, ISearchFilterValue filterValue, string locale, MarketId marketId)
        {
            ISearchConfiguration configuration = search.Client.GetConfiguration();
            SimpleValue          simpleValue;

            if ((simpleValue = filterValue as SimpleValue) != null)
            {
                IFieldConfiguration field;
                if (configuration.TryGetField(fieldName, locale, out field))
                {
                    Expression <Func <FindDocument, Filter> > matchFilter = UntypedFilterBuilder.GetMatchFilter(field, simpleValue.value);
                    search = search.Filter <FindDocument>(matchFilter);
                }
            }
            else
            {
                RangeValue rangeValue;
                if ((rangeValue = filterValue as RangeValue) != null)
                {
                    IFieldConfiguration field;
                    if (configuration.TryGetField(fieldName, locale, out field))
                    {
                        search = search.FilterFieldRange(field, rangeValue.lowerbound, rangeValue.upperbound, rangeValue.lowerboundincluded, rangeValue.upperboundincluded);
                    }
                }
                else
                {
                    PriceRangeValue priceRangeValue;
                    if ((priceRangeValue = filterValue as PriceRangeValue) == null)
                    {
                        throw new NotSupportedException(string.Format("Unrecognized search filter value type {0}.", (object)filterValue.GetType().Name));
                    }
                    IFieldConfiguration <double?> field;
                    if (configuration.TryGetPriceField(fieldName, new Mediachase.Commerce.Currency(priceRangeValue.currency.ToUpperInvariant()), marketId, out field))
                    {
                        search = search.FilterFieldRange((IFieldConfiguration)field, priceRangeValue.lowerbound, priceRangeValue.upperbound, priceRangeValue.lowerboundincluded, priceRangeValue.upperboundincluded);
                    }
                }
            }
            return(search);
        }