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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations