use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project lucene-solr by apache.
the class TestMemoryIndexAgainstRAMDir method testNullPointerException.
// LUCENE-3831
public void testNullPointerException() throws IOException {
RegexpQuery regex = new RegexpQuery(new Term("field", "worl."));
SpanQuery wrappedquery = new SpanMultiTermQueryWrapper<>(regex);
MemoryIndex mindex = randomMemoryIndex();
mindex.addField("field", new MockAnalyzer(random()).tokenStream("field", "hello there"));
// This throws an NPE
assertEquals(0, mindex.search(wrappedquery), 0.00001f);
TestUtil.checkReader(mindex.createSearcher().getIndexReader());
}
use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project lucene-solr by apache.
the class TestPayloadCheckQuery method testRewrite.
public void testRewrite() throws IOException {
SpanMultiTermQueryWrapper fiv = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "fiv*")));
SpanMultiTermQueryWrapper hund = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "hund*")));
SpanMultiTermQueryWrapper twent = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "twent*")));
SpanMultiTermQueryWrapper nin = new SpanMultiTermQueryWrapper(new WildcardQuery(new Term("field", "nin*")));
SpanNearQuery sq = new SpanNearQuery(new SpanQuery[] { fiv, hund, twent, nin }, 0, true);
List<BytesRef> payloads = new ArrayList<>();
payloads.add(new BytesRef("pos: 0"));
payloads.add(new BytesRef("pos: 1"));
payloads.add(new BytesRef("pos: 2"));
payloads.add(new BytesRef("pos: 3"));
SpanPayloadCheckQuery query = new SpanPayloadCheckQuery(sq, payloads);
// if query wasn't rewritten properly, the query would have failed with "Rewrite first!"
checkHits(query, new int[] { 529 });
}
use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.
the class TestWildcardIndex method testWildcardPlusWithCollection.
@Test
public void testWildcardPlusWithCollection() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// mein+ /+w1:2,s0 &Erfahrung
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("tokens", "s:mein+")));
// Just to make sure, Lucene internal queries treat SpanOr([]) correctly
SpanQuery soq = new SpanNearQuery(new SpanQuery[] { mtq, sq }, 1, true);
kr = ki.search(soq, (short) 10);
// As described in http://korap.github.io/Koral/, '+' is not a valid wildcard
assertEquals(0, kr.getMatches().size());
// Check the reported classed query
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(0, kr.getMatches().size());
// Check multiple distance query
mdsq = new SpanMultipleDistanceQuery(mtq, sq, constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(0, kr.getMatches().size());
}
use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.
the class TestWildcardIndex method testWildcardQuestionMark1.
@Test
public void testWildcardQuestionMark1() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// Wildcard ? means regex . (expects exactly one character)
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("tokens", "s:meine?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(3, kr.getMatches().size());
}
use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.
the class TestWildcardIndex method testWildcardQuestionMark2.
@Test
public void testWildcardQuestionMark2() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc1());
ki.commit();
// Wildcard ? means regex . (expects exactly one character)
SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(new WildcardQuery(new Term("tokens", "s:mein?")));
SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
kr = ki.search(mdsq, (short) 10);
assertEquals(1, kr.getMatches().size());
}
Aggregations