A filter that contains multiple terms.
Наследование: Filter
Пример #1
0
        public void MissingTerms_Test()
        {
            string fieldName = "field1";
            RAMDirectory rd = new RAMDirectory();
            IndexWriter w = new IndexWriter(rd, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
            for (int i = 0; i < 100; i++)
            {
                Document doc = new Document();
                int term = i * 10; //terms are units of 10;
                doc.Add(new Field(fieldName, "" + term, Field.Store.YES, Field.Index.NOT_ANALYZED));
                w.AddDocument(doc);
            }
            w.Close();
            IndexReader reader = IndexReader.Open(rd, true);

            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(fieldName, "19"));
            OpenBitSet bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(0, bits.Cardinality(), "Must match nothing");

            tf.AddTerm(new Term(fieldName, "20"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(1, bits.Cardinality(), "Must match 1");

            tf.AddTerm(new Term(fieldName, "10"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");

            tf.AddTerm(new Term(fieldName, "00"));
            bits = (OpenBitSet)tf.GetDocIdSet(reader);
            Assert.AreEqual(2, bits.Cardinality(), "Must match 2");
        }
Пример #2
0
        private Filter GetTermsFilter(String field, String text)
        {
            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(field, text));

            return tf;
        }
Пример #3
0
        public void Cachability_Test()
        {
            TermsFilter a = new TermsFilter();
            a.AddTerm(new Term("field1", "a"));
            a.AddTerm(new Term("field1", "b"));

            // original test used placing filters in a HashSet to
            // determine equality, where the FilterManager uses
            // the hash code of the filters as the key, so
            // it makes more sense to just test the equality of the 
            // hash codes.

            TermsFilter b = new TermsFilter();
            b.AddTerm(new Term("field1", "a"));
            b.AddTerm(new Term("field1", "b"));
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode(), "Hashes do not match");

            b.AddTerm(new Term("field1", "a")); //duplicate term
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode(), "Hashes do not match");

            b.AddTerm(new Term("field1", "c"));
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode(), "Hashes match");
        }
 /// <summary>
 ///     Creates the query.
 /// </summary>
 /// <param name="field">The field.</param>
 /// <param name="value">The value.</param>
 /// <returns></returns>
 public static Filter CreateTermsFilter(string field, AttributeFilterValue value)
 {
     object val = value.Id;
     var query = new TermsFilter();
     query.AddTerm(new Term(field, ConvertToSearchable(val, false)));
     return query;
 }
Пример #5
0
 public void ExOnBits()
 {
     TermsFilter a = new TermsFilter();
     a.AddTerm(new Term("field1", "a"));
     a.AddTerm(new Term("field1", "b"));
     BitArray b = a.Bits(null);
 }
Пример #6
0
        private Filter GetTermsFilter(String field, String text, bool old)
        {
            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(field, text));
            if (old)
            {
                return GetOldBitSetFilter(tf);
            }

            return tf;
        }