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

            Assert.IsNull(f.GetDocIdSet(context, (context.AtomicReader).LiveDocs), "A inverse range should return the null instance");
            f = NumericRangeFilter.NewInt64Range("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.NewInt64Range("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");
        }
示例#2
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.NewInt64Range(field, precisionStep, lower, upper, true, true);
            NumericRangeFilter <long> f = NumericRangeFilter.NewInt64Range(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.MultiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE;
                    topDocs = Searcher.Search(q, null, NoDocs, Sort.INDEXORDER);
                    break;

                case 1:
                    type = " (constant score boolean rewrite)";
                    q.MultiTermRewriteMethod = 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).GetNumericValue(), "First doc" + type);
                doc = Searcher.Doc(sd[sd.Length - 1].Doc);
                Assert.AreEqual((1 + count) * Distance + StartOffset, (long)doc.GetField(field).GetNumericValue(), "Last doc" + type);
            }
        }