Search in sources :

Example 6 with SpanNextQuery

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

the class TestNextIndex method indexExample5.

/**
 * Multiple atomic indices
 * Skip to a greater doc#
 */
@Test
public void indexExample5() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), new SpanTermQuery(new Term("base", "s:b")));
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 4, kr.getMatch(0).startPos);
    assertEquals("EndPos", 6, kr.getMatch(0).endPos);
    // Match #1
    assertEquals("doc-number", 0, kr.getMatch(1).getLocalDocID());
    assertEquals("StartPos", 1, kr.getMatch(1).startPos);
    assertEquals("EndPos", 3, kr.getMatch(1).endPos);
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:d")));
    kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 2, kr.getMatch(0).startPos);
    assertEquals("EndPos", 4, kr.getMatch(0).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 7 with SpanNextQuery

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

the class TestNextIndex method indexExample4.

@Test
public void indexExample4() throws IOException {
    KrillIndex ki = new KrillIndex();
    // abcabcabac
    // abc<x>abc<x>a</x>b</x>ac
    FieldDocument fd = new FieldDocument();
    fd.addString("ID", "doc-1");
    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|<>:x$<b>64<i>3<i>7<i>7<b>0]" + "[(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]<>:x$<b>64<i>6<i>8<i>8<b>0]" + "[(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);
    // xbz<x>xbzx</x>bxz
    fd = new FieldDocument();
    fd.addString("ID", "doc-2");
    fd.addTV("base", "xbzxbzxbxz", "[(0-1)s:x|i:x|_0$<i>0<i>1|-:t$<i>10]" + "[(1-2)s:b|i:b|_1$<i>1<i>2]" + "[(2-3)s:z|i:z|_2$<i>2<i>3]" + "[(3-4)s:x|i:x|_3$<i>3<i>4|<>:x$<b>64<i>3<i>7<i>7<b>0]" + "[(4-5)s:b|i:b|_4$<i>4<i>5]" + "[(5-6)s:z|i:z|_5$<i>5<i>6]" + "[(6-7)s:x|i:x|_6$<i>6<i>7]" + "[(7-8)s:b|i:b|_7$<i>7<i>8]" + "[(8-9)s:x|i:x|_8$<i>8<i>9]" + "[(9-10)s:z|i:z|_9$<i>9<i>10]");
    ki.addDoc(fd);
    ki.commit();
    SpanQuery sq;
    Result kr;
    sq = new SpanNextQuery(new SpanElementQuery("base", "x"), new SpanTermQuery(new Term("base", "s:b")));
    kr = ki.search(sq, (short) 10);
    assertEquals("TotalResults", kr.getTotalResults(), 2);
    assertEquals("abc[[abcab]]ac", kr.getMatch(0).getSnippetBrackets());
    assertEquals("xbz[[xbzxb]]xz", kr.getMatch(1).getSnippetBrackets());
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanElementQuery("base", "x"));
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 1);
    assertEquals("ab[[cabca]]bac", kr.getMatch(0).getSnippetBrackets());
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:z")), new SpanElementQuery("base", "x"));
    kr = ki.search(sq, (short) 10);
    assertEquals(1, kr.getTotalResults());
    assertEquals("xb[[zxbzx]]bxz", kr.getMatch(0).getSnippetBrackets());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) 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 8 with SpanNextQuery

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

the class TestNextIndex method indexExample9.

@Test
public void indexExample9() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(new SpanOrQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))), new SpanTermQuery(new Term("base", "s:c")));
    Result kr = ki.search(sq, (short) 10);
    assertEquals(0, kr.getMatch(0).getStartPos());
    assertEquals(2, kr.getMatch(0).getEndPos());
    assertEquals(3, kr.getMatch(1).getStartPos());
    assertEquals(5, kr.getMatch(1).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 9 with SpanNextQuery

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

the class TestNextIndex method indexExample6.

/**
 * Skip to NextSpan
 */
@Test
public void indexExample6() throws IOException {
    KrillIndex ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), new SpanTermQuery(new Term("base", "s:b"))));
    Result kr = ki.search(sq, (short) 10);
    assertEquals("totalResults", kr.getTotalResults(), 1);
    assertEquals("doc-number", 2, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos", 3, kr.getMatch(0).endPos);
    sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:c")), new SpanNextQuery(new SpanFocusQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:d")), (byte) 1), (byte) 1), new SpanFocusQuery(new SpanClassQuery(new SpanTermQuery(new Term("base", "s:b")), (byte) 2), (byte) 2)));
    kr = ki.search(sq, (short) 10);
    assertEquals("doc-number", 2, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 0, kr.getMatch(0).startPos);
    assertEquals("EndPos", 3, kr.getMatch(0).endPos);
// for (Match km : kr.getMatches()) {
// System.out.println(km.getStartPos() + "," + km.getEndPos()
// + " "
// + km.getSnippetBrackets());
// }
}
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) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Result(de.ids_mannheim.korap.response.Result) Test(org.junit.Test)

Example 10 with SpanNextQuery

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

the class TestUnorderedDistanceIndex method testCase8.

/**
 * Multiple NextSpans in the same first span position
 */
@Test
public void testCase8() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(new SpanTermQuery(new Term("base", "s:d")), createQuery("s:c", "s:e", 1, 2, false));
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 3);
    assertEquals(0, kr.getMatch(1).getStartPos());
    assertEquals(4, kr.getMatch(1).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Aggregations

SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)36 Test (org.junit.Test)35 Term (org.apache.lucene.index.Term)34 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)34 KrillIndex (de.ids_mannheim.korap.KrillIndex)31 SpanQuery (org.apache.lucene.search.spans.SpanQuery)31 Result (de.ids_mannheim.korap.response.Result)15 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)9 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)6 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)6 SpanRepetitionQuery (de.ids_mannheim.korap.query.SpanRepetitionQuery)6 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)3 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)3 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)2 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)2 SpanSegmentQuery (de.ids_mannheim.korap.query.SpanSegmentQuery)2 ArrayList (java.util.ArrayList)2 SpanOrQuery (org.apache.lucene.search.spans.SpanOrQuery)2 Krill (de.ids_mannheim.korap.Krill)1 KrillQuery (de.ids_mannheim.korap.KrillQuery)1