protected virtual IFilter ConvertPriceRangeFilter(PriceRangeFilter priceRangeFilter, IList <string> valueIds, ProductSearchCriteria criteria) { IFilter result = null; if (string.IsNullOrEmpty(criteria.Currency) || priceRangeFilter.Currency.EqualsInvariant(criteria.Currency)) { var knownValues = priceRangeFilter.Values ?.Where(v => valueIds.Contains(v.Id, StringComparer.OrdinalIgnoreCase)) .ToArray(); if (knownValues != null && knownValues.Any()) { var filters = knownValues .Select(v => FiltersHelper.CreatePriceRangeFilter(priceRangeFilter.Currency, criteria.Pricelists, v.Lower, v.Upper, v.IncludeLower, v.IncludeUpper)) .Where(f => f != null) .ToList(); result = filters.Or(); } else { // Unknown term values should produce empty result result = new IdsFilter { Values = new[] { string.Empty } }; } } return(result); }
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 AggregationRequest GetPriceRangeFilterValueAggregationRequest(PriceRangeFilter priceRangeFilter, RangeFilterValue value, IEnumerable <IFilter> existingFilters, IList <string> pricelists) { var valueFilter = FiltersHelper.CreatePriceRangeFilter(priceRangeFilter.Currency, pricelists, value.Lower, value.Upper, value.IncludeLower, value.IncludeUpper); var result = new TermAggregationRequest { Id = $"{priceRangeFilter.Key}-{value.Id}", Filter = existingFilters.And(valueFilter) }; return(result); }