Search in sources :

Example 6 with SpanMultipleDistanceQuery

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

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

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

Example 9 with SpanMultipleDistanceQuery

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

the class TestSampleIndex method testMultipleDistanceWithWildcards.

@Test
public void testMultipleDistanceWithWildcards() throws IOException, QueryException {
    WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:meine*"));
    SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
    // meine* /+w1:2 &Erfahrung
    SpanQuery tdq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("w", 1, 2, true, false), true);
    kr = sample.search(tdq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    assertEquals(107, kr.getMatch(0).getStartPos());
    assertEquals(109, kr.getMatch(0).getEndPos());
    assertEquals(132566, kr.getMatch(1).getStartPos());
    assertEquals(132569, kr.getMatch(1).getEndPos());
    assertEquals(161393, kr.getMatch(2).getStartPos());
    assertEquals(161396, kr.getMatch(2).getEndPos());
    assertEquals(10298, kr.getMatch(3).getStartPos());
    assertEquals(10301, kr.getMatch(3).getEndPos());
    // meine* /+s0 &Erfahrung
    SpanQuery edq = new SpanDistanceQuery(mtq, sq, TestMultipleDistanceIndex.createConstraint("tokens", "base/s:s", 0, 0, true, false), true);
    kr = sample.search(edq, (short) 20);
    assertEquals(18, kr.getMatches().size());
    // meine* /+w1:2,s0 &Erfahrung
    SpanQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
    kr = sample.search(mdsq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    // check SpanQueryWrapper generated query
    SpanQueryWrapper sqwi = getJSONQuery(getClass().getResource("/queries/bugs/cosmas_wildcards.jsonld").getFile());
    SpanQuery jsq = sqwi.toQuery();
    assertEquals(mdsq.toString(), jsq.toString());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) Term(org.apache.lucene.index.Term) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 10 with SpanMultipleDistanceQuery

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

the class TestMultipleDistanceIndex method testQueryWithWildCard.

@Test
public void testQueryWithWildCard() throws IOException {
    // meine* /+w1:2,s0 &Erfahrung
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc5());
    ki.commit();
    // Check simple rewriting
    WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:Meine*"));
    SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
    assertEquals(wcquery.toString(), "tokens:s:Meine*");
    kr = ki.search(mtq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    // Check rewriting in multidistance query
    SpanQuery sq = new SpanTermQuery(new Term("tokens", "l:Erfahrung"));
    kr = ki.search(sq, (short) 10);
    assertEquals(4, kr.getMatches().size());
    List<DistanceConstraint> constraints = new ArrayList<DistanceConstraint>();
    constraints.add(createConstraint("w", 1, 2, true, false));
    constraints.add(createConstraint("tokens", "s", 0, 0, true, false));
    SpanQuery mdsq = new SpanMultipleDistanceQuery(mtq, sq, constraints, true, true);
    assertEquals(mdsq.toString(), "spanMultipleDistance(SpanMultiTermQueryWrapper(tokens:s:Meine*), " + "tokens:l:Erfahrung, [(w[1:2], ordered, notExcluded), (s[0:0], " + "ordered, notExcluded)])");
    kr = ki.search(mdsq, (short) 10);
    assertEquals(3, kr.getMatches().size());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    // Check skipping with multiple documents
    ki.addDoc(createFieldDoc6());
    ki.addDoc(createFieldDoc7());
    ki.addDoc(createFieldDoc8());
    ki.commit();
    kr = ki.search(mdsq, (short) 10);
    assertEquals(6, kr.getMatches().size());
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) ArrayList(java.util.ArrayList) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)14 Term (org.apache.lucene.index.Term)12 Test (org.junit.Test)12 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)11 KrillIndex (de.ids_mannheim.korap.KrillIndex)10 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)10 SpanQuery (org.apache.lucene.search.spans.SpanQuery)8 WildcardQuery (org.apache.lucene.search.WildcardQuery)7 RegexpQuery (org.apache.lucene.search.RegexpQuery)4 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)3 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)2 ArrayList (java.util.ArrayList)2 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)2 Krill (de.ids_mannheim.korap.Krill)1 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)1 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)1 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)1 Result (de.ids_mannheim.korap.response.Result)1 QueryException (de.ids_mannheim.korap.util.QueryException)1 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)1