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
        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");
        }
예제 #3
0
        private Filter GetTermsFilter(String field, String text)
        {
            TermsFilter tf = new TermsFilter();
            tf.AddTerm(new Term(field, text));

            return tf;
        }
예제 #4
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");
        }
예제 #5
0
        private Filter GetTermsFilter(String field, String text)
        {
            TermsFilter tf = new TermsFilter();

            tf.AddTerm(new Term(field, text));

            return(tf);
        }
예제 #6
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);
        }
예제 #7
0
        /// <summary>
        /// Gets a Filter to restrict results to documents that are mapped from objects of the given type.
        /// </summary>
        /// <param name="type">
        /// The Type to get the filter for.
        /// </param>
        /// <returns>
        /// An instance of Filter.
        /// </returns>
        public static Filter GetTypeFilter(Type type)
        {
            TermsFilter filter = new TermsFilter(
                new Term(Documents.ObjectMappingExtensions.FieldActualType, Utils.GetTypeName(type)),
                new Term(Documents.ObjectMappingExtensions.FieldStaticType, Utils.GetTypeName(type)));

            return(filter);
        }
예제 #8
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);
        }
예제 #9
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if ((obj == null) || !(obj is TermsFilter))
            {
                return(false);
            }
            TermsFilter test = (TermsFilter)obj;

            return(terms == test.terms || (terms != null && terms.Equals(test.terms)));
        }
예제 #10
0
        public override bool Equals(Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if ((obj == null) || !(obj is TermsFilter))
            {
                return(false);
            }
            TermsFilter test = (TermsFilter)obj;

            // TODO: Does SortedSet have an issues like List<T>?  see EquatableList in Support
            return(terms == test.terms || (terms != null && terms.Equals(test.terms)));
        }
        /// <summary>
        /// Gets a Filter to restrict results to documents that are mapped from objects of the given type.
        /// </summary>
        /// <param name="type">
        /// The Type to get the filter for.
        /// </param>
        /// <param name="kind">
        /// The kind of type to restrict the filter on.
        /// </param>
        /// <returns>
        /// An instance of Filter.
        /// </returns>
        public static Filter GetTypeFilter(Type type, DocumentObjectTypeKind kind)
        {
            TermsFilter filter = new TermsFilter();

            switch (kind)
            {
            case DocumentObjectTypeKind.Actual:
                filter.AddTerm(new Term(Documents.ObjectMappingExtensions.FieldActualType, Utils.GetTypeName(type)));
                break;

            case DocumentObjectTypeKind.Static:
                filter.AddTerm(new Term(Documents.ObjectMappingExtensions.FieldStaticType, Utils.GetTypeName(type)));
                break;

            default:
                Debug.Fail("Unsupported DocumentObjectType: " + kind);
                throw new NotSupportedException(String.Format("The DocumentObjectType '{0}' is not supported.", kind));
            }

            return(filter);
        }
예제 #12
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");
        }
예제 #13
0
 /// <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;
 }
예제 #14
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);
 }
예제 #15
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;
        }