Search in sources :

Example 86 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestUnorderedDistanceIndex method testCase2.

/**
 * Multiple documents
 * Ensure same doc
 * Both candidate lists are empty, but there is a span left in the
 * doc
 * Both candidate lists are empty, but there are more matches in
 * the doc
 *
 * @throws IOException
 */
@Test
public void testCase2() throws IOException {
    // System.out.println("testcase 2");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq = createQuery("s:c", "s:d", 1, 2, false);
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 6);
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 87 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestUnorderedDistanceIndex method testCase4.

/**
 * Skip to
 */
@Test
public void testCase4() throws IOException {
    // System.out.println("testcase 4");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanQuery sq = new SpanNextQuery(createQuery("s:d", "s:e", 1, 2, false), new SpanTermQuery(new Term("base", "s:f")));
    kr = ki.search(sq, (short) 10);
    assertEquals(kr.getTotalResults(), 2);
    assertEquals(2, kr.getMatch(0).getLocalDocID());
    assertEquals(2, kr.getMatch(0).getStartPos());
    assertEquals(6, kr.getMatch(0).getEndPos());
    assertEquals(3, kr.getMatch(1).getStartPos());
    assertEquals(6, 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)

Example 88 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestUnorderedDistanceIndex method testCase7.

/**
 * Nested distance queries
 */
@Test
public void testCase7() throws IOException {
    // System.out.println("testcase 7");
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.commit();
    SpanQuery sq = createQuery("s:c", "s:d", 1, 2, false);
    SpanQuery sq2 = new SpanDistanceQuery(sq, new SpanTermQuery(new Term("base", "s:e")), new DistanceConstraint(1, 2, true, false), true);
    kr = ki.search(sq2, (short) 10);
    assertEquals(kr.getTotalResults(), 3);
    assertEquals(5, kr.getMatch(0).getStartPos());
    assertEquals(9, kr.getMatch(0).getEndPos());
    assertEquals(1, kr.getMatch(1).getLocalDocID());
    assertEquals(0, kr.getMatch(1).getStartPos());
    assertEquals(3, kr.getMatch(1).getEndPos());
    assertEquals(0, kr.getMatch(2).getStartPos());
    assertEquals(4, kr.getMatch(2).getEndPos());
}
Also used : SpanTermQuery(org.apache.lucene.search.spans.SpanTermQuery) SpanDistanceQuery(de.ids_mannheim.korap.query.SpanDistanceQuery) DistanceConstraint(de.ids_mannheim.korap.query.DistanceConstraint) Term(org.apache.lucene.index.Term) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 89 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex 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)

Example 90 with KrillIndex

use of de.ids_mannheim.korap.KrillIndex in project Krill by KorAP.

the class TestUnorderedElementDistanceIndex method testCase6.

/**
 * Subspans occurrences are in the same positions.
 */
@Test
public void testCase6() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc5());
    ki.commit();
    SpanQuery sq = createQuery("s", "s:b", "s:e", 1, 2, false);
    kr = ki.search(sq, (short) 10);
    assertEquals(8, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).startPos);
    assertEquals(3, kr.getMatch(0).endPos);
    assertEquals(0, kr.getMatch(1).startPos);
    assertEquals(5, kr.getMatch(1).endPos);
    assertEquals(1, kr.getMatch(2).startPos);
    assertEquals(3, kr.getMatch(2).endPos);
    assertEquals(1, kr.getMatch(3).startPos);
    assertEquals(4, kr.getMatch(3).endPos);
    assertEquals(1, kr.getMatch(4).startPos);
    assertEquals(5, kr.getMatch(4).endPos);
    assertEquals(2, kr.getMatch(5).startPos);
    assertEquals(7, kr.getMatch(5).endPos);
    assertEquals(3, kr.getMatch(6).startPos);
    assertEquals(5, kr.getMatch(6).endPos);
    assertEquals(4, kr.getMatch(7).startPos);
    assertEquals(7, kr.getMatch(7).endPos);
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Aggregations

KrillIndex (de.ids_mannheim.korap.KrillIndex)321 Test (org.junit.Test)310 Result (de.ids_mannheim.korap.response.Result)143 SpanQuery (org.apache.lucene.search.spans.SpanQuery)132 Term (org.apache.lucene.index.Term)93 SpanTermQuery (org.apache.lucene.search.spans.SpanTermQuery)84 Krill (de.ids_mannheim.korap.Krill)82 QueryBuilder (de.ids_mannheim.korap.query.QueryBuilder)56 SpanElementQuery (de.ids_mannheim.korap.query.SpanElementQuery)42 KrillCollection (de.ids_mannheim.korap.KrillCollection)39 TestSimple.getJsonString (de.ids_mannheim.korap.TestSimple.getJsonString)38 SpanNextQuery (de.ids_mannheim.korap.query.SpanNextQuery)37 Match (de.ids_mannheim.korap.response.Match)37 FieldDocument (de.ids_mannheim.korap.index.FieldDocument)33 JsonNode (com.fasterxml.jackson.databind.JsonNode)28 DistanceConstraint (de.ids_mannheim.korap.query.DistanceConstraint)27 SpanQueryWrapper (de.ids_mannheim.korap.query.wrap.SpanQueryWrapper)26 SpanClassQuery (de.ids_mannheim.korap.query.SpanClassQuery)25 SpanDistanceQuery (de.ids_mannheim.korap.query.SpanDistanceQuery)20 SpanWithinQuery (de.ids_mannheim.korap.query.SpanWithinQuery)18