Search in sources :

Example 96 with KrillIndex

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

the class TestDistanceIndex method testSkipTo.

@Test
public void testSkipTo() 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 97 with KrillIndex

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

the class TestElementDistanceIndex method testNoMoreSecondSpans.

@Test
public void testNoMoreSecondSpans() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc5());
    ki.commit();
    // c or b
    SpanOrQuery soq = new SpanOrQuery(new SpanTermQuery(new Term("tokens", "s:c")), new SpanTermQuery(new Term("tokens", "s:b")));
    // d /s0(c or b)
    SpanElementQuery e = new SpanElementQuery("tokens", "s");
    SpanDistanceQuery sdq = new SpanDistanceQuery(new SpanTermQuery(new Term("tokens", "s:d")), soq, new DistanceConstraint(e, 0, 0, true, false), true);
    kr = ki.search(sdq, (short) 10);
    assertEquals(0, kr.getTotalResults());
}
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) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 98 with KrillIndex

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

the class TestElementDistanceIndex method testNoElementSpans.

@Test
public void testNoElementSpans() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc3());
    ki.addDoc(createFieldDoc5());
    ki.commit();
    // c or e
    SpanOrQuery soq = new SpanOrQuery(new SpanTermQuery(new Term("tokens", "s:c")), new SpanTermQuery(new Term("tokens", "s:e")));
    // (c or e) /s0 d
    SpanElementQuery e = new SpanElementQuery("tokens", "s");
    SpanDistanceQuery sdq = new SpanDistanceQuery(soq, new SpanTermQuery(new Term("tokens", "s:d")), new DistanceConstraint(e, 0, 0, true, false), true);
    kr = ki.search(sdq, (short) 10);
}
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) SpanOrQuery(org.apache.lucene.search.spans.SpanOrQuery) KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanElementQuery(de.ids_mannheim.korap.query.SpanElementQuery) Test(org.junit.Test)

Example 99 with KrillIndex

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

the class TestElementDistanceIndex method testCase1.

/**
 * Multiple documents
 * Ensure terms and elements are in the same doc
 * Ensure terms are in elements
 * Check filter candidate list
 */
@Test
public void testCase1() throws IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc3());
    ki.commit();
    SpanQuery sq;
    sq = createQuery("s", "s:b", "s:c", 1, 1, true);
    kr = ki.search(sq, (short) 10);
    assertEquals(4, kr.getTotalResults());
    assertEquals(0, kr.getMatch(0).startPos);
    assertEquals(3, kr.getMatch(0).endPos);
    assertEquals(4, kr.getMatch(1).startPos);
    assertEquals(7, kr.getMatch(1).endPos);
    assertEquals(3, kr.getMatch(2).startPos);
    assertEquals(5, kr.getMatch(2).endPos);
    assertEquals(2, kr.getMatch(3).startPos);
    assertEquals(4, kr.getMatch(3).endPos);
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) SpanQuery(org.apache.lucene.search.spans.SpanQuery) Test(org.junit.Test)

Example 100 with KrillIndex

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

the class TestElementDistanceIndex method testCase6.

/**
 * Test query from json (2)
 */
@Test
public void testCase6() throws Exception {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc0());
    ki.addDoc(createFieldDoc1());
    ki.addDoc(createFieldDoc2());
    ki.commit();
    SpanQueryWrapper sqwi;
    sqwi = new QueryBuilder("tokens").tag("base/s:t");
    kr = ki.search(sqwi.toQuery(), (short) 10);
    assertEquals(kr.getTotalResults(), 1);
    assertEquals("[[ecebdc]]", kr.getMatch(0).getSnippetBrackets());
    String jsonPath = getClass().getResource("/queries/distances/in-same-t.jsonld").getFile();
    sqwi = getJsonQuery(jsonPath);
    assertEquals("spanElementDistance(tokens:s:c, tokens:s:e, [(base/s:t[0:0], ordered, notExcluded)])", sqwi.toQuery().toString());
    kr = ki.search(sqwi.toQuery(), (short) 10);
    // Is 1 correct or
    assertEquals(1, kr.getTotalResults());
    // should it not be
    // ordered?
    assertEquals("[[ec]]ebdc", kr.getMatch(0).getSnippetBrackets());
}
Also used : SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Aggregations

KrillIndex (de.ids_mannheim.korap.KrillIndex)320 Test (org.junit.Test)309 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