Search in sources :

Example 41 with SpanQuery

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 };
}
Also used : WildcardQuery(org.apache.lucene.search.WildcardQuery) Query(org.apache.lucene.search.Query) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) WildcardQuery(org.apache.lucene.search.WildcardQuery) MultiTermQuery(org.apache.lucene.search.MultiTermQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanFirstQuery(org.apache.lucene.search.spans.SpanFirstQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanNearQuery(org.apache.lucene.search.spans.SpanNearQuery)

Example 42 with SpanQuery

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());
}
Also used : Krill(de.ids_mannheim.korap.Krill) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) FieldDocument(de.ids_mannheim.korap.index.FieldDocument) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 43 with SpanQuery

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());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 44 with SpanQuery

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());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 45 with SpanQuery

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());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

SpanQuery (org.apache.lucene.search.spans.SpanQuery)316 Test (org.junit.Test)217 Term (org.apache.lucene.index.Term)127 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)126 KrillIndex (de.ids_mannheim.korap.KrillIndex)110 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)65 SpanNearQuery (org.apache.lucene.search.spans.SpanNearQuery)52 Result (de.ids_mannheim.korap.response.Result)48 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)39 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)35 ArrayList (java.util.ArrayList)34 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)32 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)31 Query (org.apache.lucene.search.Query)30 IndexReader (org.apache.lucene.index.IndexReader)19 BooleanQuery (org.apache.lucene.search.BooleanQuery)19 IndexSearcher (org.apache.lucene.search.IndexSearcher)18 SpanBoostQuery (org.apache.lucene.search.spans.SpanBoostQuery)18 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)18 Document (org.apache.lucene.document.Document)17