Add() public method

Add a filter clause.
public Add ( FilterClause filterClause ) : void
filterClause FilterClause The clause to add.
return void
Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
        public void TestMustAndMustNot()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetTermsFilter("inStock", "N"), Occur.MUST));
            booleanFilter.Add(new FilterClause(GetTermsFilter("price", "030"), Occur.MUST_NOT));
            TstFilterCard("MUST_NOT wins over MUST for same docs", 0, booleanFilter);
        }
Ejemplo n.º 3
0
        public void TestShoulds()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "010", "020"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "020", "030"), Occur.SHOULD));
            TstFilterCard("Shoulds are Ored together", 5, booleanFilter);
        }
Ejemplo n.º 4
0
        public void TestShouldsAndMust()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "010", "020"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "020", "030"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetTermsFilter("accessRights", "admin"), Occur.MUST));
            TstFilterCard("Shoulds Ored but MUST", 3, booleanFilter);
        }
Ejemplo n.º 5
0
        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());
        }
Ejemplo n.º 6
0
        public void ExOnBits_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));

            BitArray bits = b.Bits(this.reader);
        }
Ejemplo n.º 7
0
        public void TestShouldsAndMustsAndMustNot()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "030", "040"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetTermsFilter("accessRights", "admin"), Occur.MUST));
            booleanFilter.Add(new FilterClause(GetRangeFilter("date", "20050101", "20051231"), Occur.MUST));
            booleanFilter.Add(new FilterClause(GetTermsFilter("inStock", "N"), Occur.MUST_NOT));
            TstFilterCard("Shoulds Ored but MUSTs ANDED and MustNot", 0, booleanFilter);
        }
Ejemplo n.º 8
0
        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);
            }
        }
Ejemplo n.º 9
0
        public void TestShouldsAndMustNot()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "010", "020"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetRangeFilter("price", "020", "030"), Occur.SHOULD));
            booleanFilter.Add(new FilterClause(GetTermsFilter("inStock", "N"), Occur.MUST_NOT));
            TstFilterCard("Shoulds Ored but AndNot", 4, booleanFilter);

            booleanFilter.Add(new FilterClause(GetTermsFilter("inStock", "Maybe"), Occur.MUST_NOT));
            TstFilterCard("Shoulds Ored but AndNots", 3, booleanFilter);
        }
Ejemplo n.º 10
0
        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);
            }
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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);
            }
        }
Ejemplo n.º 13
0
        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");
        }
Ejemplo n.º 14
0
        public void TestJustMust()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetTermsFilter("accessRights", "admin"), Occur.MUST));
            TstFilterCard("MUST", 3, booleanFilter);
        }
Ejemplo n.º 15
0
        public void TestJustMustNot()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetTermsFilter("inStock", "N"), Occur.MUST_NOT));
            TstFilterCard("MUST_NOT", 4, booleanFilter);
        }
Ejemplo n.º 16
0
        public void TestShould()
        {
            BooleanFilter booleanFilter = new BooleanFilter();

            booleanFilter.Add(new FilterClause(GetTermsFilter("price", "030"), Occur.SHOULD));
            TstFilterCard("Should retrieves only 1 doc", 1, booleanFilter);
        }
Ejemplo n.º 17
0
        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);
            }
        }
Ejemplo n.º 18
0
        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);
            }
        }
Ejemplo n.º 19
0
        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);
            }
        }
Ejemplo n.º 20
0
        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);
            }
        }
Ejemplo n.º 21
0
        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);
            }
        }
Ejemplo n.º 22
0
        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;
        }
Ejemplo n.º 23
0
        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;
        }
Ejemplo n.º 25
0
        /// <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;
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
 /// <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;
 }
Ejemplo n.º 28
0
        /// <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;
        }
Ejemplo n.º 29
0
 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);
 }
Ejemplo n.º 30
0
 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);
 }
Ejemplo n.º 31
0
 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());
 }
Ejemplo n.º 32
0
 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);
 }
Ejemplo n.º 33
0
 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);
 }
Ejemplo n.º 34
0
 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());
 }
Ejemplo n.º 35
0
 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);
 }
Ejemplo n.º 36
0
 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);
 }
Ejemplo n.º 37
0
 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);
 }
Ejemplo n.º 38
0
        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);
            }

        }
Ejemplo n.º 39
0
        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);
            }
        }
Ejemplo n.º 40
0
        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);
            }
        }
Ejemplo n.º 41
0
        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");
        }
Ejemplo n.º 42
0
        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);
            }
        }
Ejemplo n.º 43
0
 public void TestJustNullDocIdSets()
 {
     BooleanFilter booleanFilter = new BooleanFilter();
     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(GetNullDISIFilter(), BooleanClause.Occur.MUST);
     TstFilterCard(@"A MUST filter that returns a null DISI should never return documents", 0, booleanFilter);
     booleanFilter = new BooleanFilter();
     booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.SHOULD);
     TstFilterCard(@"A single SHOULD filter that returns a null DIS should never return documents", 0, booleanFilter);
     booleanFilter = new BooleanFilter();
     booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.SHOULD);
     TstFilterCard(@"A single SHOULD filter that returns a null DISI should never return documents", 0, booleanFilter);
     booleanFilter = new BooleanFilter();
     booleanFilter.Add(GetNullDISFilter(), BooleanClause.Occur.MUST_NOT);
     TstFilterCard(@"A single MUST_NOT filter that returns a null DIS should be invisible", 5, booleanFilter);
     booleanFilter = new BooleanFilter();
     booleanFilter.Add(GetNullDISIFilter(), BooleanClause.Occur.MUST_NOT);
     TstFilterCard(@"A single MUST_NOT filter that returns a null DIS should be invisible", 5, booleanFilter);
 }
Ejemplo n.º 44
0
        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);
            }
        }
Ejemplo n.º 45
0
 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);
 }
Ejemplo n.º 46
0
        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());
        }
Ejemplo n.º 47
0
 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);
 }
Ejemplo n.º 48
0
        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);
            }
        }
Ejemplo n.º 49
0
 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);
 }