public virtual void TestPrefix()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match "jumps over extremely very lazy broxn dog"
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
     Assert.AreEqual(1, Searcher.Search(sfq, 10).TotalHits);
 }
 public virtual void TestWildcard()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "bro?n"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match quick brown fox
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 2);
     Assert.AreEqual(1, Searcher.Search(sfq, 10).TotalHits);
 }
 public virtual void TestFuzzy()
 {
     FuzzyQuery fq = new FuzzyQuery(new Term("field", "broan"));
     SpanQuery sfq = new SpanMultiTermQueryWrapper<MultiTermQuery>(fq);
     // will not match quick brown fox
     SpanPositionRangeQuery sprq = new SpanPositionRangeQuery(sfq, 3, 6);
     Assert.AreEqual(2, Searcher.Search(sprq, 10).TotalHits);
 }
        public virtual void TestNoSuchMultiTermsInSpanFirst()
        {
            //this hasn't been a problem
            FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(fuzzyNoSuch);
            SpanQuery spanFirst = new SpanFirstQuery(spanNoSuch, 10);

            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(wcNoSuch);
            spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(rgxNoSuch);
            spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(prfxNoSuch);
            spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);
        }
        public virtual void TestNoSuchMultiTermsInOr()
        {
            //test to make sure non existent multiterms aren't throwing null pointer exceptions
            FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(fuzzyNoSuch);
            SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
            SpanOrQuery near = new SpanOrQuery(new SpanQuery[] { term, spanNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            //flip
            near = new SpanOrQuery(new SpanQuery[] { spanNoSuch, term });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(wcNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanWCNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(rgxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanRgxNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(prfxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanPrfxNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch });
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

            near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch });
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);
        }
 public virtual void TestFuzzy2()
 {
     // maximum of 1 term expansion
     FuzzyQuery fq = new FuzzyQuery(new Term("field", "broan"), 1, 0, 1, false);
     SpanQuery sfq = new SpanMultiTermQueryWrapper<MultiTermQuery>(fq);
     // will only match jumps over lazy broun dog
     SpanPositionRangeQuery sprq = new SpanPositionRangeQuery(sfq, 0, 100);
     Assert.AreEqual(1, Searcher.Search(sprq, 10).TotalHits);
 }