public void TestCombinedNullDocIdSets() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.MUST); booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.MUST); TstFilterCard(@"A MUST filter that returns a null DIS should never return documents", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.MUST); booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.MUST); TstFilterCard(@"A MUST filter that returns a null DISI should never return documents", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.SHOULD); TstFilterCard(@"A SHOULD filter that returns a null DIS should be invisible", 1, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.SHOULD); TstFilterCard(@"A SHOULD filter that returns a null DISI should be invisible", 1, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.MUST); booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"A MUST_NOT filter that returns a null DIS should be invisible", 1, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.MUST); booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"A MUST_NOT filter that returns a null DISI should be invisible", 1, booleanFilter); }
public void Should_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("price", "030", old), BooleanClause.Occur.SHOULD)); TstFilterCard("Should retrieves only 1 doc", 1, booleanFilter); } }
public static Filter CreateQuery(ISearchCriteria criteria, ISearchFilter filter, Occur clause) { var values = filter.GetValues(); if (values == null) return null; var query = new BooleanFilter(); foreach (var value in values) { var valueQuery = CreateQueryForValue(criteria, filter, value); query.Add(new FilterClause(valueQuery, Occur.SHOULD)); } return query; }
public virtual Filter GetFilter(XmlElement e) { BooleanFilter bf = new BooleanFilter(); XmlNodeList nl = e.ChildNodes; for (int i = 0; i < nl.Count; i++) { XmlNode node = nl.Item(i); if (node.LocalName.Equals("Clause", StringComparison.Ordinal)) { XmlElement clauseElem = (XmlElement)node; BooleanClause.Occur occurs = BooleanQueryBuilder.GetOccursValue(clauseElem); XmlElement clauseFilter = DOMUtils.GetFirstChildOrFail(clauseElem); Filter f = factory.GetFilter(clauseFilter); bf.Add(new FilterClause(f, occurs)); } } return bf; }
/// <summary> /// Builds the query. /// </summary> /// <param name="criteria">The criteria.</param> /// <returns></returns> public virtual object BuildQuery(ISearchCriteria criteria) { var queryBuilder = new QueryBuilder(); var queryFilter = new BooleanFilter(); var query = new BooleanQuery(); queryBuilder.Query = query; queryBuilder.Filter = queryFilter; if (criteria.CurrentFilters != null) { foreach (var filter in criteria.CurrentFilters) { // Skip currencies that are not part of the filter if (filter.GetType() == typeof(PriceRangeFilter)) // special filtering { var currency = (filter as PriceRangeFilter).Currency; if (!currency.Equals(criteria.Currency, StringComparison.OrdinalIgnoreCase)) { continue; } } var filterQuery = LuceneQueryHelper.CreateQuery(criteria, filter, Occur.SHOULD); // now add other values that should also be counted? if (filterQuery != null) { var clause = new FilterClause(filterQuery, Occur.MUST); queryFilter.Add(clause); } } } return queryBuilder; }
public void TestMustAndMustNot() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"inStock", @"N"), BooleanClause.Occur.MUST); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"MUST_NOT wins over MUST for same docs", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetWrappedTermQuery(@"inStock", @"N"), BooleanClause.Occur.MUST); booleanFilter.Add(GetWrappedTermQuery(@"price", @"030"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"MUST_NOT wins over MUST for same docs", 0, booleanFilter); }
/// <summary> /// Creates the price range query. /// </summary> /// <param name="priceLists">The price lists.</param> /// <param name="index">The index.</param> /// <param name="field">The field.</param> /// <param name="currency">The currency.</param> /// <param name="lowerbound">The lowerbound.</param> /// <param name="upperbound">The upperbound.</param> /// <param name="lowerboundincluded"> /// if set to <c>true</c> [lowerboundincluded]. /// </param> /// <param name="upperboundincluded"> /// if set to <c>true</c> [upperboundincluded]. /// </param> /// <returns></returns> private static BooleanFilter CreatePriceRangeQuery( string[] priceLists, int index, string field, string currency, string lowerbound, string upperbound, bool lowerboundincluded, bool upperboundincluded) { var query = new BooleanFilter(); // create left part var filter = new TermRangeFilter( string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}", field, currency, priceLists[index - 1].ToLower()), "*", "*", true, false); var leftClause = new FilterClause(filter, Occur.MUST_NOT); query.Add(leftClause); // create right part if (index == priceLists.Length) // last element { //var rangefilter = NumericRangeFilter.; var filter2 = new TermRangeFilter( string.Format(CultureInfo.InvariantCulture, "{0}_{1}_{2}", field, currency, priceLists[index - 1].ToLower()), lowerbound, upperbound, lowerboundincluded, upperboundincluded); var rightClause = new FilterClause(filter2, Occur.MUST); query.Add(rightClause); } else { query.Add(new FilterClause( CreatePriceRangeQuery( priceLists, index + 1, field, currency, lowerbound, upperbound, lowerboundincluded, upperboundincluded), Occur.SHOULD)); } return query; }
/// <summary> /// Creates the query. /// </summary> /// <param name="criteria">The search criteria.</param> /// <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; } // 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(CultureInfo.InvariantCulture, "{0}_{1}_{2}", field, currency, priceListId), ConvertToSearchable(lowerbound), upper, lowerboundincluded, upperboundincluded); query.Add(new FilterClause(filter, Occur.SHOULD)); if (pls.Length > 1) { var q = CreatePriceRangeQuery( pls, 1, field, currency, ConvertToSearchable(lowerbound), upper, lowerboundincluded, upperboundincluded); query.Add(new FilterClause(q, Occur.SHOULD)); } return query; }
/// <summary> /// Creates the query. /// </summary> /// <param name="field">The field.</param> /// <param name="value">The value.</param> /// <returns></returns> public static Filter CreateQuery(string field, CategoryFilterValue value) { var query = new BooleanFilter(); if (!string.IsNullOrEmpty(value.Outline)) { // workaround since there is no wildcard filter in current lucene version var outline = value.Outline.TrimEnd('*'); var nodeQuery = new PrefixFilter(new Term(field, outline.ToLower())); query.Add(new FilterClause(nodeQuery, Occur.MUST)); } return query; }
public void ShouldsAndMustsAndMustNot_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "030", "040", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("accessRights", "admin", old), BooleanClause.Occur.MUST)); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("date", "20050101", "20051231", old), BooleanClause.Occur.MUST)); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", old), BooleanClause.Occur.MUST_NOT)); TstFilterCard("Shoulds Ored but MUSTs ANDED and MustNot", 0, booleanFilter); } }
public void TestShoulds() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); TstFilterCard(@"Shoulds are Ored together", 5, booleanFilter); }
public void TestToStringOfWrappedBooleanFilters() { BooleanFilter orFilter = new BooleanFilter(); BooleanFilter stockFilter = new BooleanFilter(); stockFilter.Add(new FilterClause(GetTermsFilter(@"inStock", @"Y"), BooleanClause.Occur.MUST)); stockFilter.Add(new FilterClause(GetTermsFilter(@"barCode", @"12345678"), BooleanClause.Occur.MUST)); orFilter.Add(new FilterClause(stockFilter, BooleanClause.Occur.SHOULD)); BooleanFilter productPropertyFilter = new BooleanFilter(); productPropertyFilter.Add(new FilterClause(GetTermsFilter(@"isHeavy", @"N"), BooleanClause.Occur.MUST)); productPropertyFilter.Add(new FilterClause(GetTermsFilter(@"isDamaged", @"Y"), BooleanClause.Occur.MUST)); orFilter.Add(new FilterClause(productPropertyFilter, BooleanClause.Occur.SHOULD)); BooleanFilter composedFilter = new BooleanFilter(); composedFilter.Add(new FilterClause(orFilter, BooleanClause.Occur.MUST)); assertEquals(@"BooleanFilter(+BooleanFilter(BooleanFilter(+inStock:Y +barCode:12345678) BooleanFilter(+isHeavy:N +isDamaged:Y)))", composedFilter.ToString()); }
public void JustMustNot_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", old), BooleanClause.Occur.MUST_NOT)); TstFilterCard("MUST_NOT", 4, booleanFilter); } }
public void TestShouldsAndMustsAndMustNot() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"030", @"040"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); booleanFilter.Add(GetRangeFilter(@"date", @"20050101", @"20051231"), BooleanClause.Occur.MUST); booleanFilter.Add(GetTermsFilter(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but MUSTs ANDED and MustNot", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"030", @"040"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetWrappedTermQuery(@"accessRights", @"admin"), BooleanClause.Occur.MUST); booleanFilter.Add(GetRangeFilter(@"date", @"20050101", @"20051231"), BooleanClause.Occur.MUST); booleanFilter.Add(GetWrappedTermQuery(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but MUSTs ANDED and MustNot", 0, booleanFilter); }
public void TestToStringOfBooleanFilterContainingTermsFilter() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"inStock", @"N"), BooleanClause.Occur.MUST); booleanFilter.Add(GetTermsFilter(@"isFragile", @"Y"), BooleanClause.Occur.MUST); assertEquals(@"BooleanFilter(+inStock:N +isFragile:Y)", booleanFilter.ToString()); }
public void TestShouldsAndMusts() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); booleanFilter.Add(GetRangeFilter(@"date", @"20040101", @"20041231"), BooleanClause.Occur.MUST); TstFilterCard(@"Shoulds Ored but MUSTs ANDED", 1, booleanFilter); }
public void TestShouldsAndMustNot() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but AndNot", 4, booleanFilter); booleanFilter.Add(GetTermsFilter(@"inStock", @"Maybe"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but AndNots", 3, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetWrappedTermQuery(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but AndNot", 4, booleanFilter); booleanFilter.Add(GetWrappedTermQuery(@"inStock", @"Maybe"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"Shoulds Ored but AndNots", 3, booleanFilter); }
public void TestShouldsAndMust() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@"Shoulds Ored but MUST", 3, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetRangeFilter(@"price", @"010", @"020"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetRangeFilter(@"price", @"020", @"030"), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetWrappedTermQuery(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@"Shoulds Ored but MUST", 3, booleanFilter); }
public void ShouldsAndMustNot_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "010", "020", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "020", "030", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", old), BooleanClause.Occur.MUST_NOT)); TstFilterCard("Shoulds Ored but AndNot", 4, booleanFilter); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("inStock", "Maybe", old), BooleanClause.Occur.MUST_NOT)); TstFilterCard("Shoulds Ored but AndNots", 3, booleanFilter); } }
public void HashEquality() { BooleanFilter a = new BooleanFilter(); a.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", false), BooleanClause.Occur.MUST)); a.Add(new BooleanFilterClause(GetTermsFilter("price", "030", false), BooleanClause.Occur.MUST_NOT)); BooleanFilter b = new BooleanFilter(); b.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", false), BooleanClause.Occur.MUST)); b.Add(new BooleanFilterClause(GetTermsFilter("price", "030", false), BooleanClause.Occur.MUST_NOT)); Assert.AreEqual(a.GetHashCode(), b.GetHashCode(), "Hashes do not match"); }
public void ShouldsAndMust_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "010", "020", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "020", "030", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("accessRights", "admin", old), BooleanClause.Occur.MUST)); TstFilterCard("Shoulds Ored but MUST", 3, booleanFilter); } }
public void TestNonMatchingShouldsAndMusts() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetEmptyFilter(), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@">0 shoulds with no matches should return no docs", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@">0 shoulds with no matches should return no docs", 0, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.SHOULD); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@">0 shoulds with no matches should return no docs", 0, booleanFilter); }
public void JustMust_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("accessRights", "admin", old), BooleanClause.Occur.MUST)); TstFilterCard("MUST", 3, booleanFilter); } }
public void TestShould() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"price", @"030"), BooleanClause.Occur.SHOULD); TstFilterCard(@"Should retrieves only 1 doc", 1, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetWrappedTermQuery(@"price", @"030"), BooleanClause.Occur.SHOULD); TstFilterCard(@"Should retrieves only 1 doc", 1, booleanFilter); }
public void MustAndMustNot_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", old), BooleanClause.Occur.MUST)); booleanFilter.Add(new BooleanFilterClause(GetTermsFilter("price", "030", old), BooleanClause.Occur.MUST_NOT)); TstFilterCard("MUST_NOT wins over MUST for same docs", 0, booleanFilter); } }
public void TestEmpty() { BooleanFilter booleanFilter = new BooleanFilter(); TstFilterCard(@"empty BooleanFilter returns no results", 0, booleanFilter); }
public void ToString_Test() { BooleanFilter b = new BooleanFilter(); b.Add(new BooleanFilterClause(GetTermsFilter("inStock", "N", false), BooleanClause.Occur.MUST)); b.Add(new BooleanFilterClause(GetTermsFilter("price", "030", false), BooleanClause.Occur.MUST_NOT)); b.Add(new BooleanFilterClause(GetRangeFilter("price", "030", "040", false), BooleanClause.Occur.SHOULD)); Assert.AreEqual("BooleanFilter( price:[030 TO 040] +( inStock:N ) -( price:030 ))", b.ToString()); }
public void TestJustMust() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@"MUST", 3, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetWrappedTermQuery(@"accessRights", @"admin"), BooleanClause.Occur.MUST); TstFilterCard(@"MUST", 3, booleanFilter); }
public void Shoulds_Test() { for (int i = 0; i < 2; i++) { bool old = (i == 0); BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "010", "020", old), BooleanClause.Occur.SHOULD)); booleanFilter.Add(new BooleanFilterClause(GetRangeFilter("price", "020", "030", old), BooleanClause.Occur.SHOULD)); TstFilterCard("Shoulds are Ored together", 5, booleanFilter); } }
public void TestJustMustNot() { BooleanFilter booleanFilter = new BooleanFilter(); booleanFilter.Add(GetTermsFilter(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"MUST_NOT", 4, booleanFilter); booleanFilter = new BooleanFilter(); booleanFilter.Add(GetWrappedTermQuery(@"inStock", @"N"), BooleanClause.Occur.MUST_NOT); TstFilterCard(@"MUST_NOT", 4, booleanFilter); }