Exemple #1
0
        protected virtual IList <IFilter> GetFilters(CategorySearchCriteria criteria)
        {
            var result = new List <IFilter>();

            if (!string.IsNullOrEmpty(criteria.SearchPhrase))
            {
                var parseResult = _searchPhraseParser.Parse(criteria.SearchPhrase);
                criteria.SearchPhrase = parseResult.SearchPhrase;
                result.AddRange(parseResult.Filters);
            }

            if (criteria.ObjectIds != null)
            {
                result.Add(new IdsFilter {
                    Values = criteria.ObjectIds
                });
            }

            if (!string.IsNullOrEmpty(criteria.CatalogId))
            {
                result.Add(FiltersHelper.CreateTermFilter("catalog", criteria.CatalogId.ToLowerInvariant()));
            }

            result.Add(FiltersHelper.CreateOutlineFilter(criteria));

            var terms = criteria.GetTerms();

            result.AddRange(terms.Select(term => FiltersHelper.CreateTermFilter(term.Key, term.Values)));

            return(result);
        }
Exemple #2
0
        protected virtual IList <IFilter> GetPermanentFilters(ProductSearchCriteria criteria)
        {
            var result = new List <IFilter>();

            if (!string.IsNullOrEmpty(criteria.SearchPhrase))
            {
                var parseResult = _searchPhraseParser.Parse(criteria.SearchPhrase);
                criteria.SearchPhrase = parseResult.SearchPhrase;
                result.AddRange(parseResult.Filters);
            }

            if (criteria.ObjectIds != null)
            {
                result.Add(new IdsFilter {
                    Values = criteria.ObjectIds
                });
            }

            if (!string.IsNullOrEmpty(criteria.CatalogId))
            {
                result.Add(FiltersHelper.CreateTermFilter("catalog", criteria.CatalogId.ToLowerInvariant()));
            }

            result.Add(FiltersHelper.CreateOutlineFilter(criteria));

            result.Add(FiltersHelper.CreateDateRangeFilter("startdate", criteria.StartDateFrom, criteria.StartDate, false, true));

            if (criteria.EndDate != null)
            {
                result.Add(FiltersHelper.CreateDateRangeFilter("enddate", criteria.EndDate, null, false, false));
            }

            if (!criteria.ClassTypes.IsNullOrEmpty())
            {
                result.Add(FiltersHelper.CreateTermFilter("__type", criteria.ClassTypes));
            }

            if (!criteria.WithHidden)
            {
                result.Add(FiltersHelper.CreateTermFilter("status", "visible"));
            }

            if (criteria.PriceRange != null)
            {
                var range = criteria.PriceRange;
                result.Add(FiltersHelper.CreatePriceRangeFilter(criteria.Currency, null, range.Lower, range.Upper, range.IncludeLower, range.IncludeUpper));
            }

            if (criteria.GeoDistanceFilter != null)
            {
                result.Add(criteria.GeoDistanceFilter);
            }

            return(result);
        }
        protected virtual IList <KeyValuePair <string, IFilter> > GetRemovableFilters(ProductSearchCriteria criteria, IList <IFilter> permanentFilters)
        {
            var result = new List <KeyValuePair <string, IFilter> >();

            var terms = criteria.GetTerms();

            if (terms.Any())
            {
                var browseFilters = GetBrowseFilters(criteria);

                var filtersAndValues = browseFilters
                                       ?.Select(x => new { Filter = x, Values = x.GetValues() })
                                       .ToList();

                foreach (var term in terms)
                {
                    var browseFilter = browseFilters?.SingleOrDefault(x => x.Key.EqualsInvariant(term.Key));

                    // Handle special filter term with a key = "tags", it contains just values and we need to determine which filter to use
                    if (browseFilter == null && term.Key == "tags")
                    {
                        foreach (var termValue in term.Values)
                        {
                            // Try to find filter by value
                            var filterAndValues = filtersAndValues?.FirstOrDefault(x => x.Values.Any(y => y.Id.Equals(termValue)));
                            if (filterAndValues != null)
                            {
                                var filter = ConvertBrowseFilter(filterAndValues.Filter, term.Values, criteria);
                                permanentFilters.Add(filter);
                            }
                            else
                            {
                                // Unknown term values should produce empty result
                                permanentFilters.Add(new IdsFilter {
                                    Values = new[] { string.Empty }
                                });
                            }
                        }
                    }
                    else if (browseFilter != null) // Predefined filter
                    {
                        var filter = ConvertBrowseFilter(browseFilter, term.Values, criteria);
                        result.Add(new KeyValuePair <string, IFilter>(browseFilter.Key, filter));
                    }
                    else // Custom term
                    {
                        var filter = FiltersHelper.CreateTermFilter(term.Key, term.Values);
                        permanentFilters.Add(filter);
                    }
                }
            }

            return(result);
        }