Search in sources :

Example 1 with SpanSegmentQuery

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

the class TestDistanceIndex method testCase6.

/**
 * Skip to
 */
@Test
public void testCase6() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc2());
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery firstClause = createQuery("s:d", "s:e", 3, 4, true);
    kr = ki.search(firstClause, (short) 10);
    assertEquals(kr.getTotalResults(), 3);
    assertEquals(0, kr.getMatch(0).getLocalDocID());
    assertEquals(2, kr.getMatch(0).startPos);
    assertEquals(6, kr.getMatch(0).endPos);
    assertEquals(1, kr.getMatch(1).getLocalDocID());
    assertEquals(4, kr.getMatch(1).startPos);
    assertEquals(8, kr.getMatch(1).endPos);
    assertEquals(4, kr.getMatch(2).startPos);
    assertEquals(9, kr.getMatch(2).endPos);
    // The secondspans is skipped to doc# of the current firstspans
    SpanQuery sq = new SpanSegmentQuery(createQuery("s:d", "s:e", 3, 4, true), createElementQuery("y", "x", 1, 2, true));
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 1);
    assertEquals(4, kr.getMatch(0).startPos);
    assertEquals(9, kr.getMatch(0).endPos);
}
Also used : SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 2 with SpanSegmentQuery

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

the class TestSegmentIndex method testCase2.

/**
 * Matches in multiple documents.
 * Ensure the same document. The current secondspan is skipped to
 * the doc number of the firstspan.
 */
@Test
public void testCase2() throws IOException {
    // log.trace("Testcase2");
    sq = new SpanSegmentQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b")));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 3);
    // Match #0
    assertEquals("doc-number", 1, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos", 2, kr.getMatch(0).endPos);
    // Match #2
    assertEquals("doc-number", 2, kr.getMatch(2).getLocalDocID());
    assertEquals("StartPos", 2, kr.getMatch(2).startPos);
    assertEquals("EndPos", 3, kr.getMatch(2).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) Test(org.junit.Test)

Example 3 with SpanSegmentQuery

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

the class TestSegmentIndex method testCase4.

/**
 * Matching a SpanElementQuery and a SpanNextQuery
 * Multiple atomic indices
 */
@Test
public void testCase4() throws IOException {
    // log.trace("Testcase4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.commit();
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    sq = new SpanSegmentQuery(new SpanElementQuery("base", "e"), new SpanNextQuery(new SpanTermQuery(new Term("base", "s:a")), new SpanTermQuery(new Term("base", "s:b"))));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 2);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos", 5, 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);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) SpanNextQuery(de.ids_mannheim.korap.query.SpanNextQuery) Test(org.junit.Test)

Example 4 with SpanSegmentQuery

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

the class TestSegmentIndex method testCase5.

/**
 * Matching SpanElementQueries
 */
@Test
public void testCase5() throws IOException {
    // log.trace("Testcase5");
    sq = new SpanSegmentQuery(new SpanElementQuery("base", "e"), new SpanElementQuery("base", "e2"));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 1);
    // Match #0
    assertEquals("doc-number", 0, kr.getMatch(0).getLocalDocID());
    assertEquals("StartPos", 3, kr.getMatch(0).startPos);
    assertEquals("EndPos", 5, kr.getMatch(0).endPos);
}
Also used : SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 5 with SpanSegmentQuery

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

the class TestSegmentIndex method testCase1.

/**
 * Multiple matches in one document.
 */
@Test
public void testCase1() throws IOException {
    sq = new SpanSegmentQuery(new SpanTermQuery(new Term("base", "s:b")), new SpanTermQuery(new Term("base", "s:c")));
    kr = ki.search(sq, (short) 10);
    ki.close();
    assertEquals("totalResults", kr.getTotalResults(), 3);
    assertEquals("StartPos (0)", 1, kr.getMatch(0).startPos);
    assertEquals("EndPos (0)", 2, kr.getMatch(0).endPos);
    assertEquals("StartPos (1)", 4, kr.getMatch(1).startPos);
    assertEquals("EndPos (1)", 5, kr.getMatch(1).endPos);
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanSegmentQuery(de.ids_mannheim.korap.query.SpanSegmentQuery) Term(org.apache.lucene.index.Term) Test(org.junit.Test)

Aggregations

SpanSegmentQuery (de.ids_mannheim.korap.query.SpanSegmentQuery)9 Test (org.junit.Test)9 Term (org.apache.lucene.index.Term)7 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)7 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)4 KrillIndex (de.ids_mannheim.korap.KrillIndex)2 SpanFocusQuery (de.ids_mannheim.korap.query.SpanFocusQuery)2 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)2 SpanRelationQuery (de.ids_mannheim.korap.query.SpanRelationQuery)2 SpanAttributeQuery (de.ids_mannheim.korap.query.SpanAttributeQuery)1 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)1 SpanTermWithIdQuery (de.ids_mannheim.korap.query.SpanTermWithIdQuery)1 SpanWithAttributeQuery (de.ids_mannheim.korap.query.SpanWithAttributeQuery)1 SpanQuery (org.apache.lucene.search.spans.SpanQuery)1