Search in sources :

Example 16 with SpanClassQuery

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

the class TestRelationIndex method testCase9.

/**
 * Relation with specific sources and return any targets <br/>
 * Relation with specific sources and targets, return the targets
 * <br/>
 * Relation with specific sources and targets, return the sources
 *
 * @throws IOException
 */
@Test
public void testCase9() throws IOException {
    ki.addDoc(createFieldDoc2());
    ki.commit();
    // return all children of np
    SpanElementQuery seq1 = new SpanElementQuery("base", "np");
    SpanClassQuery scq1 = new SpanClassQuery(seq1, (byte) 1);
    SpanRelationQuery srq = new SpanRelationQuery(new SpanTermQuery(new Term("base", "<:child-of")), true, RelationDirection.LEFT);
    srq.setSourceClass((byte) 2);
    SpanRelationMatchQuery rm = new SpanRelationMatchQuery(srq, scq1, true);
    SpanFocusQuery rv = new SpanFocusQuery(rm, (byte) 2);
    rv.setSorted(false);
    assertEquals("focus(2: focus(#[1,2]spanSegment({2: source:spanRelation(base:<:child-of)}, {1: <base:np />})))", rv.toString());
    kr = ki.search(rv, (short) 10);
    assertEquals((long) 7, 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(2, kr.getMatch(2).getStartPos());
    assertEquals(4, kr.getMatch(2).getEndPos());
    assertEquals(3, kr.getMatch(3).getStartPos());
    assertEquals(4, kr.getMatch(3).getEndPos());
    assertEquals(4, kr.getMatch(4).getStartPos());
    assertEquals(7, kr.getMatch(4).getEndPos());
    assertEquals(5, kr.getMatch(5).getStartPos());
    assertEquals(6, kr.getMatch(5).getEndPos());
    assertEquals(6, kr.getMatch(6).getStartPos());
    assertEquals(7, kr.getMatch(6).getEndPos());
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanRelationQuery(de.ids_mannheim.korap.query.SpanRelationQuery) SpanRelationMatchQuery(de.ids_mannheim.korap.query.SpanRelationMatchQuery) Term(org.apache.lucene.index.Term) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) Test(org.junit.Test)

Example 17 with SpanClassQuery

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

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

the class TestClassIndex method indexExample1.

@Test
public void indexExample1() throws IOException {
    KrillIndex ki = new KrillIndex();
    // abcabcabac
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:a")));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("StartPos (0)", 7, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 9, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "... bcabca[[ba]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\">" + "</span>bcabca</span><span class=\"match\"><mark>ba</mark></span><span class=\"context-right" + "\">c</span>", kr.getMatch(0).getSnippetHTML());
    sq = new SpanTermQuery(new Term("base", "s:b"));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "a[[b]]cabcab ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\">a</span><span class=\"match\"><mark>" + "b</mark></span><span class=\"context-right\">cabcab<span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
    assertEquals("SnippetBrackets (1)", "abca[[b]]cabac", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (2)", 7, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("SnippetBrackets (2)", "... bcabca[[b]]ac", kr.getMatch(2).getSnippetBrackets());
    sq = new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("snippetBrackets (0)", "a[[{1:b}]]cabcab ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("snippetHTML (0)", "<span class=\"context-left\">a</span><span class=\"match\"><mark>" + "<mark class=\"class-1 level-0\">b</mark></mark></span><span class=\"context-right\">cabcab<span " + "class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
    assertEquals("snippetBrackets (1)", "abca[[{1:b}]]cabac", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (2)", 7, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("snippetBrackets (2)", "... bcabca[[{1:b}]]ac", kr.getMatch(2).getSnippetBrackets());
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "[[a{1:b}]]cabcab ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\"></span><span class=\"match\"><mark>a<mark class=\"class-1 level-0\">b</mark></mark></span><span class=\"context-right\">cabcab<span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
    assertEquals("SnippetBrackets (1)", "abc[[a{1:b}]]cabac", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (2)", 6, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("SnippetBrackets (2)", "abcabc[[a{1:b}]]ac", kr.getMatch(2).getSnippetBrackets());
    // abcabcabac
    sq = new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3));
    kr = ki.search(sq, (short) 10);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "[[{2:a}{3:b}]]cabcab ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
    assertEquals("SnippetBrackets (1)", "abc[[{2:a}{3:b}]]cabac", kr.getMatch(1).getSnippetBrackets());
    assertEquals("StartPos (2)", 6, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("SnippetBrackets (2)", "abcabc[[{2:a}{3:b}]]ac", kr.getMatch(2).getSnippetBrackets());
    // abcabcabac
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanClassQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")))), (byte) 2));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "abcabc[[a{2:b{1:a}}]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\">abcabc</span><span class=\"match\"><mark>a<mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark></span><span class=\"context-right\">c</span>", kr.getMatch(0).getSnippetHTML());
    // Offset tokens
    kr = ki.search(sq, 0, (short) 10, true, (short) 2, true, (short) 2);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "... bc[[a{2:b{1:a}}]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\"><mark>a<mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark></span><span class=\"context-right\">c</span>", kr.getMatch(0).getSnippetHTML());
    // Offset Characters
    kr = ki.search(sq, 0, (short) 10, false, (short) 2, false, (short) 2);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "... bc[[a{2:b{1:a}}]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0)", "<span class=\"context-left\"><span class=\"more\"></span>bc</span><span class=\"match\"><mark>a<mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark></span><span class=\"context-right\">c</span>", kr.getMatch(0).getSnippetHTML());
    // System.err.println(kr.toJSON());
    sq = new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), (byte) 2));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 6, kr.getMatch(1).endPos);
    assertEquals("Document count", 1, ki.numberOf("base", "documents"));
    assertEquals("Token count", 10, ki.numberOf("base", "t"));
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanClassQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:c")))));
    kr = ki.search(sq, (short) 2);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    assertEquals("StartPos (0)", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 3, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 6, kr.getMatch(1).endPos);
    assertEquals(1, ki.numberOf("base", "documents"));
    assertEquals(10, ki.numberOf("base", "t"));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 19 with SpanClassQuery

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

the class TestMatchIndex method indexExampleExtend.

@Test
public void indexExampleExtend() throws IOException {
    KrillIndex ki = new KrillIndex();
    // abcabcabac
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3);
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    Match km = kr.getMatch(0);
    assertEquals("StartPos (0)", 1, km.startPos);
    assertEquals("EndPos (0)", 2, km.endPos);
    assertEquals("SnippetBrackets (0)", "a[[{3:b}]]cabcab ...", km.getSnippetBrackets());
    sq = new SpanFocusQuery(new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3), (byte) 2);
    kr = ki.search(sq, (short) 10);
    km = kr.getMatch(0);
    assertEquals("StartPos (0)", 0, km.startPos);
    assertEquals("EndPos (0)", 1, km.endPos);
    assertEquals("SnippetBrackets (0)", "[[{2:a}]]bcabca ...", km.getSnippetBrackets());
// TODO: Check ID
}
Also used : SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Match(de.ids_mannheim.korap.response.Match) Test(org.junit.Test)

Example 20 with SpanClassQuery

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

the class TestMatchIndex method indexExample1.

@Test
public void indexExample1() throws IOException {
    KrillIndex ki = new KrillIndex();
    // abcabcabac
    FieldDocument fd = new FieldDocument();
    fd.addTV("base", "abcabcabac", "[(0-1)s:a|i:a|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:c|i:c|_2$<i>2<i>3]" + "[(3-4)s:a|i:a|_3$<i>3<i>4]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:c|i:c|_5$<i>5<i>6]" + "[(6-7)s:a|i:a|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:a|i:a|_8$<i>8<i>9]" + "[(9-10)s:c|i:c|_9$<i>9<i>10]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a"))));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("StartPos (0)", 7, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 9, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "... bcabca[[b{1:a}]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("Test no 'more' context", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\"><mark>b<mark class=\"class-1 level-0\">a</mark></mark></span><span class=\"context-right\">c</span>", kr.getMatch(0).getSnippetHTML());
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")))));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("StartPos (0)", 8, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 9, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "... cabcab[[{1:a}]]c", kr.getMatch(0).getSnippetBrackets());
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")), (byte) 2), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 3)), (byte) 3);
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "a[[{3:b}]]cabcab ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("<span class=\"context-left\">a</span><span class=\"match\"><mark><mark class=\"class-3 level-0\">b</mark></mark></span><span class=\"context-right\">cabcab<span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
    assertEquals("SnippetBrackets (1)", "abca[[{3:b}]]cabac", kr.getMatch(1).getSnippetBrackets());
    assertEquals("<span class=\"context-left\">abca</span><span class=\"match\"><mark><mark class=\"class-3 level-0\">b</mark></mark></span><span class=\"context-right\">cabac</span>", kr.getMatch(1).getSnippetHTML());
    assertEquals("StartPos (2)", 7, kr.getMatch(2).startPos);
    assertEquals("EndPos (2)", 8, kr.getMatch(2).endPos);
    assertEquals("SnippetBrackets (2)", "... bcabca[[{3:b}]]ac", kr.getMatch(2).getSnippetBrackets());
    // abcabcabac
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanClassQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:a")))), (byte) 2)), (byte) 2);
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "... bcabca[[{2:b{1:a}}]]c", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0) 1", "<span class=\"context-left\"><span class=\"more\"></span>bcabca</span><span class=\"match\"><mark><mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark></span><span class=\"context-right\">c</span>", kr.getMatch(0).getSnippetHTML());
    // Offset tokens
    kr = ki.search(sq, 0, (short) 10, true, (short) 2, true, (short) 2);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "... ca[[{2:b{1:a}}]]c", kr.getMatch(0).getSnippetBrackets());
    // Offset Characters
    kr = ki.search(sq, 0, (short) 10, false, (short) 1, false, (short) 0);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("SnippetBrackets (0)", "... a[[{2:b{1:a}}]] ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("SnippetHTML (0) 2", "<span class=\"context-left\"><span class=\"more\"></span>a</span><span class=\"match\"><mark><mark class=\"class-2 level-0\">b<mark class=\"class-1 level-1\">a</mark></mark></mark></span><span class=\"context-right\"><span class=\"more\"></span></span>", kr.getMatch(0).getSnippetHTML());
    // Don't match the expected class!
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 1), new SpanClassQuery(new SpanTermQuery(new Term("base", "s:c")), (byte) 2)), (byte) 3);
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 0);
    sq = new SpanFocusQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanClassQuery(new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:c"))))));
    kr = ki.search(sq, (short) 2);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 3, kr.getMatch(0).endPos);
    assertEquals("SnippetBrackets (0)", "a[[{1:bc}]]abcaba ...", kr.getMatch(0).getSnippetBrackets());
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 6, kr.getMatch(1).endPos);
    assertEquals("SnippetBrackets (1)", "abca[[{1:bc}]]abac", kr.getMatch(1).getSnippetBrackets());
    assertEquals(1, ki.numberOf("base", "documents"));
    assertEquals(10, ki.numberOf("base", "t"));
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanClassQuery(de.ids_mannheim.korap.query.SpanClassQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanFocusQuery(de.ids_mannheim.korap.query.SpanFocusQuery) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Result(de.ids_mannheim.korap.response.Result) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Aggregations

SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)32 Test (org.junit.Test)30 Term (org.apache.lucene.index.Term)25 KrillIndex (de.ids_mannheim.korap.KrillIndex)24 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)16 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)15 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)14 SpanQuery (org.apache.lucene.search.spans.SpanQuery)14 SpanMultipleDistanceQuery (de.ids_mannheim.korap.query.SpanMultipleDistanceQuery)10 SpanMultiTermQueryWrapper (org.apache.lucene.search.spans.SpanMultiTermQueryWrapper)10 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)9 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)8 Result (de.ids_mannheim.korap.response.Result)8 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)7 SpanClassFilterQuery (de.ids_mannheim.korap.query.SpanClassFilterQuery)6 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)6 SpanRelationMatchQuery (de.ids_mannheim.korap.query.SpanRelationMatchQuery)6 WildcardQuery (org.apache.lucene.search.WildcardQuery)6 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)4 RegexpQuery (org.apache.lucene.search.RegexpQuery)4