private static string GetRangeFilterValueExpression(RangeFilterValue filterValue, string azureFieldName) { var lowerCondition = filterValue.IncludeLower ? "ge" : "gt"; var upperCondition = filterValue.IncludeUpper ? "le" : "lt"; return(GetRangeFilterExpression(azureFieldName, filterValue.Lower, lowerCondition, filterValue.Upper, upperCondition)); }
private static RangeFilterValue[] GetRangeFilterValues(IList <string> bounds) { var result = new List <RangeFilterValue>(); if (bounds?.Any() == true) { var sortedBounds = SortStringsAsNumbers(bounds).ToList(); sortedBounds.Add(null); string previousBound = null; foreach (var bound in sortedBounds) { var value = new RangeFilterValue { Id = previousBound == null ? $"under-{bound}" : bound == null ? $"over-{previousBound}" : $"{previousBound}-{bound}", Lower = previousBound, Upper = bound, IncludeLower = true, IncludeUpper = false, }; result.Add(value); previousBound = bound; } } return(result.Any() ? result.ToArray() : null); }
/// <summary> /// Creates the query. /// </summary> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns></returns> public static Filter CreateQuery(ISearchCriteria criteria, string field, RangeFilterValue value) { var query = new BooleanFilter(); object lowerbound = value.Lower; object upperbound = value.Upper; const bool lowerboundincluded = true; const bool upperboundincluded = false; var currency = criteria.Currency.ToLower(); var upper = upperbound == null?NumericUtils.LongToPrefixCoded(long.MaxValue) : ConvertToSearchable(upperbound); // format is "fieldname_store_currency_pricelist" string[] pls = null; var searchCriteria = criteria as CatalogIndexedSearchCriteria; if (searchCriteria != null) { pls = searchCriteria.Pricelists; } var parentPriceList = String.Empty; // Create filter of type // price_USD_pricelist1:[100 TO 200} (-price_USD_pricelist1:[* TO *} +(price_USD_pricelist2:[100 TO 200} (-price_USD_pricelist2:[* TO *} (+price_USD_pricelist3[100 TO 200})))) if (pls == null || !pls.Any()) { return(null); } var priceListId = pls[0].ToLower(); var filter = new TermRangeFilter( String.Format("{0}_{1}_{2}", field, currency, priceListId), ConvertToSearchable(lowerbound), upper, lowerboundincluded, upperboundincluded); query.Add(new FilterClause(filter, Occur.SHOULD)); if (pls.Count() > 1) { var q = CreatePriceRangeQuery( pls, 1, field, currency, ConvertToSearchable(lowerbound), upper, lowerboundincluded, upperboundincluded); query.Add(new FilterClause(q, Occur.SHOULD)); } return(query); }
private static TermRangeQuery CreateTermRangeQuery(string fieldName, RangeFilterValue value) { var lower = string.IsNullOrEmpty(value.Lower) ? null : value.Lower; var upper = string.IsNullOrEmpty(value.Upper) ? null : value.Upper; return(CreateTermRangeQuery(fieldName, lower, upper, value.IncludeLower, value.IncludeUpper)); }
/// <summary> /// Creates the query. /// </summary> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns></returns> public static Filter CreateTermRangeFilter(string field, RangeFilterValue value) { object lowerbound = value.Lower; object upperbound = value.Upper; var query = new TermRangeFilter(field, ConvertToSearchable(lowerbound), ConvertToSearchable(upperbound), true, false); return(query); }
private static RangeFilterValue CreateRange(string desciption, string key, string lower, string upper, string lang) { var val = new RangeFilterValue { Id = key }; if (lower != null) { val.Lower = lower; } if (!String.IsNullOrEmpty(upper)) { val.Upper = upper; } var disp = new FilterValueDisplay { Value = desciption, Language = lang }; val.Displays = new[] { disp }; return(val); }
/// <summary> /// Creates the price range filter. /// </summary> /// <param name="criteria">The criteria.</param> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns></returns> public static BoolFilter <ESDocument> CreatePriceRangeFilter(ISearchCriteria criteria, string field, RangeFilterValue value) { var query = new BoolFilter <ESDocument>(); var lowerbound = value.Lower; var upperbound = value.Upper; var lowerboundincluded = true; var upperboundincluded = false; var currency = criteria.Currency.ToLower(); // format is "fieldname_store_currency_pricelist" string[] pls = null; if (criteria is CatalogIndexedSearchCriteria) { pls = ((CatalogIndexedSearchCriteria)criteria).Pricelists; } var parentPriceList = String.Empty; // Create filter of type // price_USD_pricelist1:[100 TO 200} (-price_USD_pricelist1:[* TO *} +(price_USD_pricelist2:[100 TO 200} (-price_USD_pricelist2:[* TO *} (+price_USD_pricelist3[100 TO 200})))) if (pls == null || !pls.Any()) { return(null); } var priceListId = pls[0].ToLower(); var filter = new RangeFilter <ESDocument>(); filter.Field(String.Format("{0}_{1}_{2}", field, currency, priceListId)).From(lowerbound).To(upperbound).IncludeLower(lowerboundincluded).IncludeUpper(upperboundincluded); //query.Should(q => q.ConstantScore(c => c.Filter(f => f.Range(r => filter)))); query.Should(q => q.Range(r => filter)); if (pls.Count() > 1) { var temp = CreatePriceRangeFilter(pls, 1, field, currency, lowerbound, upperbound, lowerboundincluded, upperboundincluded); query.Should(q => q.Bool(b => temp)); } //Query query = new ConstantScoreQuery(filter); return(query); }
public static string Stringify(this RangeFilterValue rageValue) { return((rageValue.Lower ?? "*") + "-" + (rageValue.Upper ?? "*")); }
private static Filter CreateRangeFilterForValue(string fieldName, RangeFilterValue value) { return(CreateRangeFilterForValue(fieldName, value.Lower, value.Upper, value.IncludeLower, value.IncludeUpper)); }