Search in sources :

Example 26 with SpanMultiTermQueryWrapper

use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.

the class TestRegexIndex method testWildcardStarRewritten.

@Test
public void testWildcardStarRewritten() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    // meine* /+w1:2,s0 &Erfahrung
    // rewritten into meine.*
    RegexpQuery wcquery = new RegexpQuery(new Term("tokens", "s:meine.*"));
    SpanMultiTermQueryWrapper<RegexpQuery> mtq = new SpanMultiTermQueryWrapper<RegexpQuery>(wcquery);
    SpanMultipleDistanceQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
    kr = ki.search(mdsq, (short) 10);
    assertEquals(4, 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 27 with SpanMultiTermQueryWrapper

use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.

the class TestRelationIndex method testRelationWithRegex.

@Test
public void testRelationWithRegex() throws IOException {
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanQuery sq;
    sq = new SpanRelationQuery(new SpanMultiTermQueryWrapper<RegexQuery>(new RegexQuery(new Term("base", ">:xip/.*"))), true, RelationDirection.RIGHT);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 7, kr.getTotalResults());
    sq = new SpanRelationQuery(new SpanMultiTermQueryWrapper<RegexQuery>(new RegexQuery(new Term("base", "<:xip/.*"))), true, RelationDirection.LEFT);
    kr = ki.search(sq, (short) 10);
    assertEquals((long) 7, kr.getTotalResults());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) RegexQuery(org.apache.lucene.sandbox.queries.regex.RegexQuery) Term(org.apache.lucene.index.Term) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 28 with SpanMultiTermQueryWrapper

use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.

the class TestSampleIndex method testWildcardStarWithCollection.

@Test
public void testWildcardStarWithCollection() throws IOException {
    // meine*
    WildcardQuery wcquery = new WildcardQuery(new Term("tokens", "s:meine*"));
    SpanMultiTermQueryWrapper<WildcardQuery> mtq = new SpanMultiTermQueryWrapper<WildcardQuery>(wcquery);
    // meine* /+w1:2,s0 &Erfahrung
    SpanQuery mdsq = new SpanMultipleDistanceQuery(new SpanClassQuery(mtq, (byte) 129), new SpanClassQuery(sq, (byte) 129), constraints, true, true);
    krillAvailabilityAll.setSpanQuery(mdsq);
    kr = sample.search(krillAvailabilityAll);
    assertEquals(4, kr.getMatches().size());
    assertEquals("match-GOE/AGI/04846-p107-109", kr.getMatch(0).getID());
    assertEquals("QAO-NC-LOC:ids", kr.getMatch(0).getAvailability());
    assertEquals("... gelesen und erzählt hat, ich in " + "[[meine Erfahrungen]] hätte mit aufnehmen sollen. " + "heute jedoch ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("match-GOE/AGD/00000-p132566-132569", kr.getMatch(1).getID());
    assertEquals("QAO-NC-LOC:ids-NU:1", kr.getMatch(1).getAvailability());
    assertEquals("... Mannes umständlich beibringen und solches " + "durch [[meine eigne Erfahrung]] bekräftigen: das " + "alles sollte nicht gelten ...", kr.getMatch(1).getSnippetBrackets());
    assertEquals("match-GOE/AGD/00000-p161393-161396", kr.getMatch(2).getID());
    assertEquals("QAO-NC-LOC:ids-NU:1", kr.getMatch(2).getAvailability());
    assertEquals("... lassen, bis er sich zuletzt an " + "[[meine sämtlichen Erfahrungen]] und Überzeugungen " + "anschloß, in welchem Sinne ...", kr.getMatch(2).getSnippetBrackets());
    assertEquals("match-GOE/AGD/06345-p10298-10301", kr.getMatch(3).getID());
    assertEquals("QAO-NC", kr.getMatch(3).getAvailability());
    assertEquals("... bis aufs Äußerste verfolgte, und, über " + "[[meine enge Erfahrung]] hinaus, nach ähnlichen Fällen " + "in der ...", kr.getMatch(3).getSnippetBrackets());
}
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) SpanMultipleDistanceQuery(de.ids_mannheim.korap.query.SpanMultipleDistanceQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 29 with SpanMultiTermQueryWrapper

use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.

the class TestSpanExpansionIndex method testQueryRewriteBug.

/**
 * Query rewrite bug
 *
 * Warning: This is not armoured by <base/s=t>!
 *
 * @throws IOException
 */
@Test
public void testQueryRewriteBug() throws IOException {
    KrillIndex ki = new KrillIndex();
    // ceccecdeec
    ki.addDoc(createFieldDoc0());
    /*
        ki.addDoc(createFieldDoc1()); // bbccdd || only not clause
        ki.addDoc(createFieldDoc2()); // beccea | only main clause
        */
    ki.commit();
    // See /queries/bugs/repetition_group_rewrite
    RegexpQuery requery = new RegexpQuery(new Term("base", "s:[ac]"), RegExp.ALL);
    SpanMultiTermQueryWrapper<RegexpQuery> query = new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
    SpanExpansionQuery seq = new SpanExpansionQuery(query, 1, 1, 1, true);
    SpanRepetitionQuery rep = new SpanRepetitionQuery(seq, 2, 2, true);
    // spanRepetition(
    // spanExpansion(
    // SpanMultiTermQueryWrapper(base:/s:[ac]/),
    // []{1, 1},
    // right
    // ){2,2}
    // )
    kr = ki.search(query, (short) 20);
    assertEquals(5, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(1, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(3, kr.getMatch(1).getEndPos());
    assertEquals(3, kr.getMatch(2).getStartPos());
    assertEquals(4, kr.getMatch(2).getEndPos());
    assertEquals(5, kr.getMatch(3).getStartPos());
    assertEquals(6, kr.getMatch(3).getEndPos());
    assertEquals(9, kr.getMatch(4).getStartPos());
    assertEquals(10, kr.getMatch(4).getEndPos());
    kr = ki.search(seq, (short) 20);
    assertEquals(5, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(2, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
    assertEquals(3, kr.getMatch(2).getStartPos());
    assertEquals(5, kr.getMatch(2).getEndPos());
    assertEquals(5, kr.getMatch(3).getStartPos());
    assertEquals(7, kr.getMatch(3).getEndPos());
    assertEquals(9, kr.getMatch(4).getStartPos());
    assertEquals(11, kr.getMatch(4).getEndPos());
    kr = ki.search(rep, (short) 20);
    assertEquals("[[cecc]]ecdeec", kr.getMatch(0).getSnippetBrackets());
    assertEquals("cec[[cecd]]eec", kr.getMatch(1).getSnippetBrackets());
    assertEquals((long) 2, kr.getTotalResults());
}
Also used : SpanRepetitionQuery(de.ids_mannheim.korap.query.SpanRepetitionQuery) SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) RegexpQuery(org.apache.lucene.search.RegexpQuery) Test(org.junit.Test)

Example 30 with SpanMultiTermQueryWrapper

use of org.apache.lucene.search.spans.SpanMultiTermQueryWrapper in project Krill by KorAP.

the class TestSpanExpansionIndex method testBugRegexExpandLeftNoMoreSpan.

@Test
public void testBugRegexExpandLeftNoMoreSpan() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc6());
    ki.commit();
    SpanTermQuery stq = new SpanTermQuery(new Term("base", "s:a"));
    RegexpQuery requery = new RegexpQuery(new Term("base", "s:[bc]"), RegExp.ALL);
    SpanMultiTermQueryWrapper<RegexpQuery> notQuery = new SpanMultiTermQueryWrapper<RegexpQuery>(requery);
    byte classNumber = 1;
    // left expansion
    SpanExpansionQuery seq = new SpanExpansionQuery(stq, notQuery, 0, 1, -1, classNumber, true);
    kr = ki.search(seq, (short) 20);
    assertEquals(9, kr.getMatches().size());
}
Also used : SpanMultiTermQueryWrapper(org.apache.lucene.search.spans.SpanMultiTermQueryWrapper) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanExpansionQuery(de.ids_mannheim.korap.query.SpanExpansionQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) RegexpQuery(org.apache.lucene.search.RegexpQuery) 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