Example #1
0
        public virtual void TestInverseRange()
        {
            AtomicReaderContext       context = (AtomicReaderContext)SlowCompositeReaderWrapper.Wrap(Searcher.IndexReader).Context;
            NumericRangeFilter <long> f       = NumericRangeFilter.NewLongRange("field8", 8, 1000L, -1000L, true, true);

            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A inverse range should return the null instance");
            f = NumericRangeFilter.NewLongRange("field8", 8, long.MaxValue, null, false, false);
            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range starting with Long.MAX_VALUE should return the null instance");
            f = NumericRangeFilter.NewLongRange("field8", 8, null, long.MinValue, false, false);
            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A exclusive range ending with Long.MIN_VALUE should return the null instance");
        }
        public virtual void  TestInverseRange()
        {
            System.Int64       tempAux  = 1000L;
            System.Int64       tempAux2 = -1000L;
            NumericRangeFilter f        = NumericRangeFilter.NewLongRange("field8", 8, tempAux, tempAux2, true, true);

            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.GetIndexReader()), "A inverse range should return the EMPTY_DOCIDSET instance");
            //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int64 tempAux3 = (long)System.Int64.MaxValue;
            f = NumericRangeFilter.NewLongRange("field8", 8, tempAux3, null, false, false);
            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.GetIndexReader()), "A exclusive range starting with Long.MAX_VALUE should return the EMPTY_DOCIDSET instance");
            //UPGRADE_TODO: The 'System.Int64' structure does not have an equivalent to NULL. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1291'"
            System.Int64 tempAux4 = (long)System.Int64.MinValue;
            f = NumericRangeFilter.NewLongRange("field8", 8, null, tempAux4, false, false);
            Assert.AreSame(DocIdSet.EMPTY_DOCIDSET, f.GetDocIdSet(searcher.GetIndexReader()), "A exclusive range ending with Long.MIN_VALUE should return the EMPTY_DOCIDSET instance");
        }
Example #3
0
        /// <summary>
        /// test for constant score + boolean query + filter, the other tests only use the constant score mode </summary>
        private void TestRange(int precisionStep)
        {
            string field = "field" + precisionStep;
            int    count = 3000;
            long   lower = (Distance * 3 / 2) + StartOffset, upper = lower + count * Distance + (Distance / 3);
            NumericRangeQuery <long>  q = NumericRangeQuery.NewLongRange(field, precisionStep, lower, upper, true, true);
            NumericRangeFilter <long> f = NumericRangeFilter.NewLongRange(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, (long)doc.GetField(field).NumericValue, "First doc" + type);
                doc = Searcher.Doc(sd[sd.Length - 1].Doc);
                Assert.AreEqual((1 + count) * Distance + StartOffset, (long)doc.GetField(field).NumericValue, "Last doc" + type);
            }
        }
        /// <summary>test for constant score + boolean query + filter, the other tests only use the constant score mode </summary>
        private void  TestRange(int precisionStep)
        {
            System.String field = "field" + precisionStep;
            int           count = 3000;
            long          lower = (distance * 3 / 2) + startOffset, upper = lower + count * distance + (distance / 3);

            System.Int64      tempAux  = (long)lower;
            System.Int64      tempAux2 = (long)upper;
            NumericRangeQuery q        = NumericRangeQuery.NewLongRange(field, precisionStep, tempAux, tempAux2, true, true);

            System.Int64       tempAux3 = (long)lower;
            System.Int64       tempAux4 = (long)upper;
            NumericRangeFilter f        = NumericRangeFilter.NewLongRange(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.SetRewriteMethod(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE);
                    topDocs = searcher.Search(q, null, noDocs, Sort.INDEXORDER);
                    terms   = q.GetTotalNumberOfTerms();
                    break;

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

                case 2:
                    type    = " (filter)";
                    topDocs = searcher.Search(new MatchAllDocsQuery(), f, noDocs, Sort.INDEXORDER);
                    terms   = f.GetTotalNumberOfTerms();
                    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);
                Assert.AreEqual(2 * distance + startOffset, System.Int64.Parse(doc.Get(field)), "First doc" + type);
                doc = searcher.Doc(sd[sd.Length - 1].doc);
                Assert.AreEqual((1 + count) * distance + startOffset, System.Int64.Parse(doc.Get(field)), "Last doc" + type);
                if (i > 0)
                {
                    Assert.AreEqual(lastTerms, terms, "Distinct term number is equal for all query types");
                }
                lastTerms = terms;
            }
        }