Search in sources :

Example 11 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery 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 12 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery 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 13 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery 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)

Example 14 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery in project Krill by KorAP.

the class TestRegexIndex method testWildcardQuestionMarkRewritten.

@Test
public void testWildcardQuestionMarkRewritten() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // meine? /+w1:2,s0 &Erfahrung
    // meine? rewritten into meine.
    SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(new RegexpQuery(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 : 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) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Example 15 with SpanClassQuery

use of de.ids_mannheim.korap.query.SpanClassQuery in project Krill by KorAP.

the class TestRegexIndex method testWildcardPlusRewritten2.

@Test
public void testWildcardPlusRewritten2() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // C2 mein+ /+w1:2,s0 &Erfahrung
    // mein+ rewritten into mein.?
    SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(new RegexpQuery(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(2, kr.getMatches().size());
}
Also used : 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) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Aggregations

SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)32 Test (org.junit.Test)30 Term (org.apache.lucene.index.Term)25 KrillIndex (de.ids_mannheim.korap.KrillIndex)24 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)16 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)15 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)14 SpanQuery (org.apache.lucene.search.spans.SpanQuery)14 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)10 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)10 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)9 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)8 Result (de.ids_mannheim.korap.response.Result)8 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)7 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)6 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)6 WildcardQuery (org.apache.lucene.search.WildcardQuery)6 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)4 RegexpQuery (org.apache.lucene.search.RegexpQuery)4