use of org.apache.lucene.search.spans.SpanQuery in project lucene-solr by apache.
the class EnwikiQueryMaker method getPrebuiltQueries.
private static Query[] getPrebuiltQueries(String field) {
WildcardQuery wcq = new WildcardQuery(new Term(field, "fo*"));
wcq.setRewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE);
// be wary of unanalyzed text
return new Query[] { new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 5), new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(new Term(field, "night")), new SpanTermQuery(new Term(field, "trading")) }, 4, false), new SpanNearQuery(new SpanQuery[] { new SpanFirstQuery(new SpanTermQuery(new Term(field, "ford")), 10), new SpanTermQuery(new Term(field, "credit")) }, 10, false), wcq };
}
use of org.apache.lucene.search.spans.SpanQuery in project Krill by KorAP.
the class TestHighlight method highlightEmptySpan.
@Test
public void highlightEmptySpan() throws IOException, QueryException {
KrillIndex ki = new KrillIndex();
// <>:s$<b>65<i>38<b>0
// <a>x<a>y<a>zhij</a>hij</a>hij</a>hij</a>
FieldDocument fd = new FieldDocument();
fd.addTV("base", "x y z h i j h i j h i j ", "[(0-3)s:x|<>:a$<b>64<i>0<i>3<i>12<b>0]" + "[(3-6)s:y|<>:a$<b>64<i>3<i>6<i>9<b>0]" + "[(6-9)s:z|<>:a$<b>64<i>6<i>9<i>6|<>:a$<b>65<i>6]" + "[(9-12)s:h<b>0]" + "[(12-15)s:i]" + "[(15-18)s:j]" + "[(18-21)s:h]" + "[(21-24)s:i]" + "[(24-27)s:j]" + "[(27-30)s:h]" + "[(30-33)s:i]" + "[(33-36)s:j]");
ki.addDoc(fd);
// Commit!
ki.commit();
QueryBuilder kq = new QueryBuilder("base");
SpanQuery q = (SpanQuery) kq.tag("a").toQuery();
Krill qs = new Krill(q);
qs.getMeta().getContext().left.setToken(true).setLength((short) 5);
qs.getMeta().getContext().right.setToken(true).setLength((short) 5);
Result kr = ki.search(qs);
assertEquals((long) 4, kr.getTotalResults());
Match km = kr.getMatch(2);
assertEquals("<span class=\"context-left\">" + "</span>" + "<span class=\"match\">" + "<mark>x y z </mark>" + "</span><span class=\"context-right\">h i j h i j h i j </span>", km.getSnippetHTML());
km = kr.getMatch(3);
assertEquals("<span class=\"context-left\"><span class=\"match\"></span></span>", km.getSnippetHTML());
}
use of org.apache.lucene.search.spans.SpanQuery in project Krill by KorAP.
the class TestDistanceExclusionIndex method testCase2.
/**
* Multiple docs, unordered
* No more secondSpans
*/
@Test
public void testCase2() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.addDoc(createFieldDoc1());
ki.commit();
SpanQuery sq;
// ---- Distance 0 to 1
sq = createQuery("s:c", "s:e", 0, 1, false);
kr = ki.search(sq, (short) 10);
assertEquals((long) 5, kr.getTotalResults());
assertEquals(1, kr.getMatch(3).getLocalDocID());
}
use of org.apache.lucene.search.spans.SpanQuery in project Krill by KorAP.
the class TestDistanceExclusionIndex method testCase4.
/**
* Unordered: firstspan in on the right side of the secondspan,
* but within max distance.
*/
@Test
public void testCase4() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc2());
ki.commit();
SpanQuery sq;
// Unordered
sq = createQuery("s:b", "s:c", 2, 2, false);
kr = ki.search(sq, (short) 10);
assertEquals((long) 1, kr.getTotalResults());
assertEquals(1, kr.getMatch(0).getStartPos());
assertEquals(2, kr.getMatch(0).getEndPos());
}
use of org.apache.lucene.search.spans.SpanQuery in project Krill by KorAP.
the class TestDistanceExclusionIndex method testCase1.
/**
* Ordered, unordered
*/
@Test
public void testCase1() throws IOException {
ki = new KrillIndex();
ki.addDoc(createFieldDoc0());
ki.commit();
SpanQuery sq;
// ordered distance 0 to 1
sq = createQuery("s:c", "s:e", 0, 1, true);
kr = ki.search(sq, (short) 10);
assertEquals((long) 3, kr.getTotalResults());
assertEquals(2, kr.getMatch(0).getStartPos());
assertEquals(3, kr.getMatch(0).getEndPos());
assertEquals(3, kr.getMatch(1).getStartPos());
assertEquals(4, kr.getMatch(1).getEndPos());
assertEquals(5, kr.getMatch(2).getStartPos());
assertEquals(6, kr.getMatch(2).getEndPos());
// Unordered
sq = createQuery("s:c", "s:e", 0, 1, false);
kr = ki.search(sq, (short) 10);
assertEquals((long) 2, kr.getTotalResults());
}
Aggregations