protected virtual IList <IFilter> GetFilters(CategoryIndexedSearchCriteria criteria) { var result = new List <IFilter>(); if (!string.IsNullOrEmpty(criteria.Keyword)) { var parseResult = _searchPhraseParser.Parse(criteria.Keyword); criteria.Keyword = parseResult.Keyword; 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); }
protected virtual IList <IFilter> GetPermanentFilters(ProductIndexedSearchCriteria criteria) { var result = new List <IFilter>(); if (!string.IsNullOrEmpty(criteria.Keyword)) { var parseResult = _searchPhraseParser.Parse(criteria.Keyword); criteria.Keyword = parseResult.Keyword; 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)); if (criteria.StartDateFrom.HasValue) { result.Add(FiltersHelper.CreateDateRangeFilter("startdate", criteria.StartDateFrom, criteria.StartDate, false, true)); } if (criteria.EndDate.HasValue) { 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, criteria.Pricelists, range.Lower, range.Upper, range.IncludeLower, range.IncludeUpper)); } if (criteria.GeoDistanceFilter != null) { result.Add(criteria.GeoDistanceFilter); } return(result); }
public virtual async Task <FiltersContainer> GetTermFiltersAsync(ProductIndexedSearchCriteria criteria) { var result = new FiltersContainer(); var terms = criteria.GetTerms(); if (terms.Any()) { var browseFilters = await _browseFilterService.GetBrowseFiltersAsync(criteria); var filtersAndValues = browseFilters ?.Select(f => new { Filter = f, Values = f.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(v => v.Id.Equals(termValue)) == true); if (filterAndValues != null) { var filter = ConvertBrowseFilter(filterAndValues.Filter, term.Values, criteria); result.PermanentFilters.Add(filter); } else { // Unknown term values should produce empty result result.PermanentFilters.Add(new IdsFilter { Values = new[] { string.Empty } }); } } } else if (browseFilter != null) // Predefined filter { var filter = ConvertBrowseFilter(browseFilter, term.Values, criteria); result.RemovableFilters.Add(new KeyValuePair <string, IFilter>(browseFilter.Key, filter)); } else // Custom term { var filter = FiltersHelper.CreateTermFilter(term.Key, term.Values); result.PermanentFilters.Add(filter); } } } return(result); }