Search in sources :

Example 6 with SpanMultiTermQueryWrapper

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());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) RegexpQuery(org.apache.lucene.search.RegexpQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery)

Example 7 with SpanMultiTermQueryWrapper

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 });
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) ArrayList(java.util.ArrayList) Term(org.apache.lucene.index.Term) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) BytesRef(org.apache.lucene.util.BytesRef)

Example 8 with SpanMultiTermQueryWrapper

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());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 9 with SpanMultiTermQueryWrapper

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());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) Test(org.junit.Test)

Example 10 with SpanMultiTermQueryWrapper

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());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) Test(org.junit.Test)

Aggregations

SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)31 Term (org.apache.lucene.index.Term)27 SpanQuery (org.apache.lucene.search.spans.SpanQuery)19 WildcardQuery (org.apache.lucene.search.WildcardQuery)15 RegexpQuery (org.apache.lucene.search.RegexpQuery)14 Test (org.junit.Test)14 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)12 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)12 KrillIndex (de.ids_mannheim.korap.KrillIndex)11 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)11 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)10 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)10 Query (org.apache.lucene.search.Query)9 BooleanQuery (org.apache.lucene.search.BooleanQuery)8 BoostQuery (org.apache.lucene.search.BoostQuery)8 TermQuery (org.apache.lucene.search.TermQuery)8 SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)8 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)7 PrefixQuery (org.apache.lucene.search.PrefixQuery)7 TermRangeQuery (org.apache.lucene.search.TermRangeQuery)7