Ejemplo n.º 1
0
        public virtual void TestInverseRange()
        {
            AtomicReaderContext      context = (AtomicReaderContext)SlowCompositeReaderWrapper.Wrap(Reader).Context;
            NumericRangeFilter <int> f       = NumericRangeFilter.NewIntRange("field8", 8, 1000, -1000, true, true);

            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A inverse range should return the null instance");
            f = NumericRangeFilter.NewIntRange("field8", 8, int.MaxValue, null, false, false);
            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range starting with Integer.MAX_VALUE should return the null instance");
            f = NumericRangeFilter.NewIntRange("field8", 8, null, int.MinValue, false, false);
            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range ending with Integer.MIN_VALUE should return the null instance");
        }
Ejemplo n.º 2
0
        public virtual void  TestInverseRange()
        {
            System.Int32             tempAux  = 1000;
            System.Int32             tempAux2 = -1000;
            NumericRangeFilter <int> f        = NumericRangeFilter.NewIntRange("field8", 8, tempAux, tempAux2, true, true);

            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.IndexReader, null), "A inverse range should return the EMPTY_DOCIDSET instance");
            //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int32 tempAux3 = (System.Int32)System.Int32.MaxValue;
            f = NumericRangeFilter.NewIntRange("field8", 8, tempAux3, null, false, false);
            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.IndexReader, null), "A exclusive range starting with Integer.MAX_VALUE should return the EMPTY_DOCIDSET instance");
            //UPGRADE_TODO: The 'System.Int32' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int32 tempAux4 = (System.Int32)System.Int32.MinValue;
            f = NumericRangeFilter.NewIntRange("field8", 8, null, tempAux4, false, false);
            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.IndexReader, null), "A exclusive range ending with Integer.MIN_VALUE should return the EMPTY_DOCIDSET instance");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// test for both constant score and boolean query, the other tests only use the constant score mode </summary>
        private void TestRange(int precisionStep)
        {
            string field = "field" + precisionStep;
            int    count = 3000;
            int    lower = (Distance * 3 / 2) + StartOffset, upper = lower + count * Distance + (Distance / 3);
            NumericRangeQuery <int>  q = NumericRangeQuery.NewIntRange(field, precisionStep, lower, upper, true, true);
            NumericRangeFilter <int> f = NumericRangeFilter.NewIntRange(field, precisionStep, lower, upper, true, true);

            for (sbyte i = 0; i < 3; i++)
            {
                TopDocs topDocs;
                string  type;
                switch (i)
                {
                case 0:
                    type = " (constant score filter rewrite)";
                    q.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
                    topDocs = Searcher.Search(q, null, NoDocs, Sort.INDEXORDER);
                    break;

                case 1:
                    type = " (constant score boolean rewrite)";
                    q.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE);
                    topDocs = Searcher.Search(q, null, NoDocs, Sort.INDEXORDER);
                    break;

                case 2:
                    type    = " (filter)";
                    topDocs = Searcher.Search(new MatchAllDocsQuery(), f, NoDocs, Sort.INDEXORDER);
                    break;

                default:
                    return;
                }
                ScoreDoc[] sd = topDocs.ScoreDocs;
                Assert.IsNotNull(sd);
                Assert.AreEqual(count, sd.Length, "Score doc count" + type);
                Document doc = Searcher.Doc(sd[0].Doc);
                Assert.AreEqual(2 * Distance + StartOffset, (int)doc.GetField(field).NumericValue, "First doc" + type);
                doc = Searcher.Doc(sd[sd.Length - 1].Doc);
                Assert.AreEqual((1 + count) * Distance + StartOffset, (int)doc.GetField(field).NumericValue, "Last doc" + type);
            }
        }
Ejemplo n.º 4
0
        public void TestIsCacheable()
        {
            Directory   dir    = new RAMDirectory();
            IndexWriter writer = new IndexWriter(dir, new KeywordAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);

            writer.Close();

            IndexReader reader = IndexReader.Open(dir, true);

            // not cacheable:
            assertDocIdSetCacheable(reader, new QueryWrapperFilter(new TermQuery(new Term("test", "value"))), false);
            // returns default empty docidset, always cacheable:
            assertDocIdSetCacheable(reader, NumericRangeFilter.NewIntRange("test", 10000, -10000, true, true), true);
            // is cacheable:
            assertDocIdSetCacheable(reader, FieldCacheRangeFilter.NewIntRange("test", 10, 20, true, true), true);
            // a openbitset filter is always cacheable
            assertDocIdSetCacheable(reader, new AnonymousFilter3(), true);

            reader.Close();
        }
Ejemplo n.º 5
0
        public virtual void TestIsCacheAble()
        {
            Directory         dir    = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);

            writer.AddDocument(new Document());
            writer.Dispose();

            IndexReader reader = SlowCompositeReaderWrapper.Wrap(DirectoryReader.Open(dir));

            // not cacheable:
            AssertDocIdSetCacheable(reader, new QueryWrapperFilter(new TermQuery(new Term("test", "value"))), false);
            // returns default empty docidset, always cacheable:
            AssertDocIdSetCacheable(reader, NumericRangeFilter.NewIntRange("test", Convert.ToInt32(10000), Convert.ToInt32(-10000), true, true), true);
            // is cacheable:
            AssertDocIdSetCacheable(reader, FieldCacheRangeFilter.NewIntRange("test", Convert.ToInt32(10), Convert.ToInt32(20), true, true), true);
            // a fixedbitset filter is always cacheable
            AssertDocIdSetCacheable(reader, new FilterAnonymousInnerClassHelper3(this), true);

            reader.Dispose();
            dir.Dispose();
        }
Ejemplo n.º 6
0
        /// <summary>test for both constant score and boolean query, the other tests only use the constant score mode </summary>
        private void  TestRange(int precisionStep)
        {
            System.String field = "field" + precisionStep;
            int           count = 3000;
            int           lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);

            System.Int32            tempAux  = (System.Int32)lower;
            System.Int32            tempAux2 = (System.Int32)upper;
            NumericRangeQuery <int> q        = NumericRangeQuery.NewIntRange(field, precisionStep, tempAux, tempAux2, true, true);

            System.Int32             tempAux3 = (System.Int32)lower;
            System.Int32             tempAux4 = (System.Int32)upper;
            NumericRangeFilter <int> f        = NumericRangeFilter.NewIntRange(field, precisionStep, tempAux3, tempAux4, true, true);
            int lastTerms = 0;

            for (sbyte i = 0; i < 3; i++)
            {
                TopDocs       topDocs;
                int           terms;
                System.String type;
                q.ClearTotalNumberOfTerms();
                f.ClearTotalNumberOfTerms();
                switch (i)
                {
                case 0:
                    type            = " (constant score filter rewrite)";
                    q.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
                    topDocs         = searcher.Search(q, null, noDocs, Sort.INDEXORDER, null);
                    terms           = q.TotalNumberOfTerms;
                    break;

                case 1:
                    type            = " (constant score boolean rewrite)";
                    q.RewriteMethod = MultiTermQuery.CONSTANT_SCORE_BOOLEAN_QUERY_REWRITE;
                    topDocs         = searcher.Search(q, null, noDocs, Sort.INDEXORDER, null);
                    terms           = q.TotalNumberOfTerms;
                    break;

                case 2:
                    type    = " (filter)";
                    topDocs = searcher.Search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER, null);
                    terms   = f.TotalNumberOfTerms;
                    break;

                default:
                    return;
                }
                System.Console.Out.WriteLine("Found " + terms + " distinct terms in range for field '" + field + "'" + type + ".");
                ScoreDoc[] sd = topDocs.ScoreDocs;
                Assert.IsNotNull(sd);
                Assert.AreEqual(count, sd.Length, "Score doc count" + type);
                Document doc = searcher.Doc(sd[0].Doc, null);
                Assert.AreEqual(2 * distance + startOffset, System.Int32.Parse(doc.Get(field, null)), "First doc" + type);
                doc = searcher.Doc(sd[sd.Length - 1].Doc, null);
                Assert.AreEqual((1 + count) * distance + startOffset, System.Int32.Parse(doc.Get(field, null)), "Last doc" + type);
                if (i > 0)
                {
                    Assert.AreEqual(lastTerms, terms, "Distinct term number is equal for all query types");
                }
                lastTerms = terms;
            }
        }