Search in sources :

Example 46 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestSpanMultiTermQueryWrapper method testNoSuchMultiTermsInNotNear.

public void testNoSuchMultiTermsInNotNear() throws Exception {
    //test to make sure non existent multiterms aren't throwing non-matching field exceptions  
    FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
    SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<>(fuzzyNoSuch);
    SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
    SpanNotQuery notNear = new SpanNotQuery(term, spanNoSuch, 0, 0);
    assertEquals(1, searcher.search(notNear, 10).totalHits);
    //flip
    notNear = new SpanNotQuery(spanNoSuch, term, 0, 0);
    assertEquals(0, searcher.search(notNear, 10).totalHits);
    //both noSuch
    notNear = new SpanNotQuery(spanNoSuch, spanNoSuch, 0, 0);
    assertEquals(0, searcher.search(notNear, 10).totalHits);
    WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
    SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
    notNear = new SpanNotQuery(term, spanWCNoSuch, 0, 0);
    assertEquals(1, searcher.search(notNear, 10).totalHits);
    RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
    SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
    notNear = new SpanNotQuery(term, spanRgxNoSuch, 1, 1);
    assertEquals(1, searcher.search(notNear, 10).totalHits);
    PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
    SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
    notNear = new SpanNotQuery(term, spanPrfxNoSuch, 1, 1);
    assertEquals(1, searcher.search(notNear, 10).totalHits);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 47 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestSpanMultiTermQueryWrapper method testPrefix.

public void testPrefix() throws Exception {
    WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
    SpanQuery swq = new SpanMultiTermQueryWrapper<>(wq);
    // will only match "jumps over extremely very lazy broxn dog"
    SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
    assertEquals(1, searcher.search(sfq, 10).totalHits);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Example 48 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestSpanMultiTermQueryWrapper method testNoSuchMultiTermsInOr.

public void testNoSuchMultiTermsInOr() throws Exception {
    //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<>(fuzzyNoSuch);
    SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
    SpanOrQuery near = new SpanOrQuery(new SpanQuery[] { term, spanNoSuch });
    assertEquals(1, searcher.search(near, 10).totalHits);
    //flip
    near = new SpanOrQuery(new SpanQuery[] { spanNoSuch, term });
    assertEquals(1, searcher.search(near, 10).totalHits);
    WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
    SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
    near = new SpanOrQuery(new SpanQuery[] { term, spanWCNoSuch });
    assertEquals(1, searcher.search(near, 10).totalHits);
    RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
    SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
    near = new SpanOrQuery(new SpanQuery[] { term, spanRgxNoSuch });
    assertEquals(1, searcher.search(near, 10).totalHits);
    PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
    SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
    near = new SpanOrQuery(new SpanQuery[] { term, spanPrfxNoSuch });
    assertEquals(1, searcher.search(near, 10).totalHits);
    near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch });
    assertEquals(0, searcher.search(near, 10).totalHits);
    near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch });
    assertEquals(0, searcher.search(near, 10).totalHits);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 49 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestSpanMultiTermQueryWrapper method testNoSuchMultiTermsInNear.

public void testNoSuchMultiTermsInNear() throws Exception {
    //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<>(fuzzyNoSuch);
    SpanQuery term = new SpanTermQuery(new Term("field", "brown"));
    SpanQuery near = new SpanNearQuery(new SpanQuery[] { term, spanNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    //flip order
    near = new SpanNearQuery(new SpanQuery[] { spanNoSuch, term }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
    SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<>(wcNoSuch);
    near = new SpanNearQuery(new SpanQuery[] { term, spanWCNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
    SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<>(rgxNoSuch);
    near = new SpanNearQuery(new SpanQuery[] { term, spanRgxNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
    SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<>(prfxNoSuch);
    near = new SpanNearQuery(new SpanQuery[] { term, spanPrfxNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    //test single noSuch
    near = new SpanNearQuery(new SpanQuery[] { spanPrfxNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
    //test double noSuch
    near = new SpanNearQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch }, 1, true);
    assertEquals(0, searcher.search(near, 10).totalHits);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) PrefixQuery(org.apache.lucene.search.PrefixQuery) FuzzyQuery(org.apache.lucene.search.FuzzyQuery) Term(org.apache.lucene.index.Term) RegexpQuery(org.apache.lucene.search.RegexpQuery)

Example 50 with WildcardQuery

use of org.apache.lucene.search.WildcardQuery in project lucene-solr by apache.

the class TestSpanMultiTermQueryWrapper method testWildcard.

public void testWildcard() throws Exception {
    WildcardQuery wq = new WildcardQuery(new Term("field", "bro?n"));
    SpanQuery swq = new SpanMultiTermQueryWrapper<>(wq);
    // will only match quick brown fox
    SpanFirstQuery sfq = new SpanFirstQuery(swq, 2);
    assertEquals(1, searcher.search(sfq, 10).totalHits);
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Term(org.apache.lucene.index.Term)

Aggregations

WildcardQuery (org.apache.lucene.search.WildcardQuery)71 Term (org.apache.lucene.index.Term)63 BooleanQuery (org.apache.lucene.search.BooleanQuery)30 PrefixQuery (org.apache.lucene.search.PrefixQuery)24 Query (org.apache.lucene.search.Query)22 FuzzyQuery (org.apache.lucene.search.FuzzyQuery)20 TermQuery (org.apache.lucene.search.TermQuery)20 Document (org.apache.lucene.document.Document)17 BoostQuery (org.apache.lucene.search.BoostQuery)15 IndexSearcher (org.apache.lucene.search.IndexSearcher)15 RegexpQuery (org.apache.lucene.search.RegexpQuery)15 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)14 PhraseQuery (org.apache.lucene.search.PhraseQuery)14 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)14 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)14 Field (org.apache.lucene.document.Field)13 IndexReader (org.apache.lucene.index.IndexReader)13 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)13 TopDocs (org.apache.lucene.search.TopDocs)13 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)13