Search in sources :

Example 81 with KrillIndex

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

the class TestFocusIndex method testFocusSortingWrapping.

@Test
public void testFocusSortingWrapping() throws QueryException, IOException {
    ki = new KrillIndex();
    ki.addDoc(createFieldDoc());
    ki.commit();
    QueryBuilder kq = new QueryBuilder("tokens");
    SpanQueryWrapper focus = kq.focus(kq.contains(kq.tag("x"), kq.or(kq.nr(1, kq.seg("s:b")), kq.nr(1, kq.seg("s:c")))));
    assertEquals("focus(1: spanContain(<tokens:x />, spanOr([{1: tokens:s:b}, {1: tokens:s:c}])),sorting)", focus.toQuery().toString());
    kr = ki.search(focus.toQuery(), (short) 10);
    assertEquals("a[[{1:b}]]cd", kr.getMatch(0).getSnippetBrackets());
    assertEquals("a[[{1:b}]]cd", kr.getMatch(1).getSnippetBrackets());
    assertEquals("ab[[{1:c}]]d", kr.getMatch(2).getSnippetBrackets());
    assertEquals("ab[[{1:c}]]d", kr.getMatch(3).getSnippetBrackets());
    assertEquals(4, kr.getTotalResults());
    focus = kq.focus(kq.startswith(kq.tag("x"), kq.or(kq.nr(1, kq.seg("s:b")), kq.nr(1, kq.seg("s:c")))));
    assertEquals("focus(1: spanStartsWith(<tokens:x />, spanOr([{1: tokens:s:b}, {1: tokens:s:c}])))", focus.toQuery().toString());
    kr = ki.search(focus.toQuery(), (short) 10);
    assertEquals("a[[{1:b}]]cd", kr.getMatch(0).getSnippetBrackets());
    assertEquals(1, kr.getTotalResults());
}
Also used : QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 82 with KrillIndex

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

the class TestFocusIndex method testFocusInNext.

@Test
public void testFocusInNext() throws QueryException, IOException {
    ki = new KrillIndex();
    // 1xMatch
    ki.addDoc(simpleFieldDoc("abcd"));
    ki.addDoc(simpleFieldDoc("acbcbcacb"));
    ki.addDoc(simpleFieldDoc("yyy"));
    // 2xMatch
    ki.addDoc(simpleFieldDoc("acbcbcacbabcdcabcd"));
    ki.addDoc(simpleFieldDoc("acbcbcacb"));
    ki.addDoc(simpleFieldDoc("bca"));
    // 1xMatch
    ki.addDoc(simpleFieldDoc("bcadbcadbcadbcadabcdbcadbca"));
    ki.commit();
    ki.addDoc(simpleFieldDoc("bca"));
    ki.addDoc(simpleFieldDoc("adbca"));
    ki.addDoc(simpleFieldDoc("dbc"));
    ki.addDoc(simpleFieldDoc("bca"));
    // 1xMatch
    ki.addDoc(simpleFieldDoc("abcd"));
    ki.commit();
    QueryBuilder kq = new QueryBuilder("base");
    SpanQueryWrapper focus = kq.seq(kq.seg("s:b"), kq.focus(kq.seq(kq.seg("s:a"), kq.seg("s:b"), kq.nr(1, kq.seg("s:c")))));
    assertEquals("spanNext(base:s:b, focus(1: spanNext(spanNext(base:s:a, base:s:b), {1: base:s:c})))", focus.toQuery().toString());
    kr = ki.search(focus.toQuery(), (short) 10);
    assertEquals(5, kr.getTotalResults());
}
Also used : QueryBuilder(de.ids_mannheim.korap.query.QueryBuilder) SpanQueryWrapper(de.ids_mannheim.korap.query.wrap.SpanQueryWrapper) KrillIndex(de.ids_mannheim.korap.KrillIndex) Test(org.junit.Test)

Example 83 with KrillIndex

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

the class TestIndexRevision method testIndexRevisionLeafTempFile.

public void testIndexRevisionLeafTempFile() throws IOException {
    String x1, x2, x3;
    Path tmpdir = Files.createTempDirectory("wikileaf");
    KrillIndex ki = new KrillIndex(new MMapDirectory(tmpdir));
    assertEquals("null", ki.getFingerprint());
    ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
    ki.commit();
    List<LeafReaderContext> contexts = ki.reader().leaves();
    assertEquals(1, contexts.size());
    x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_0(5.0.0):c1", x1);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00003.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00004.json.gz"), true);
    ki.commit();
    ki.addDoc(getClass().getResourceAsStream("/wiki/00006.json.gz"), true);
    ki.commit();
    contexts = ki.reader().leaves();
    assertEquals(3, contexts.size());
    x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_0(5.0.0):c1", x1);
    x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_1(5.0.0):c3", x2);
    x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_2(5.0.0):c1", x3);
    assertTrue(ki.delDocs("title", "A (Band)"));
    ki.commit();
    assertEquals(false, ki.isReaderOpen());
    contexts = ki.reader().leaves();
    assertEquals(3, contexts.size());
    x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_0(5.0.0):c1", x1);
    x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_1(5.0.0):c3/1:delGen=1", x2);
    x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_2(5.0.0):c1", x3);
    String fingerp = "241/XHj/9ZxeO5Lm3zZ+iw==";
    assertEquals(fingerp, ki.getFingerprint());
    ki.close();
    // Reload index
    ki = new KrillIndex(new MMapDirectory(tmpdir));
    assertEquals(fingerp, ki.getFingerprint());
    contexts = ki.reader().leaves();
    assertEquals(3, contexts.size());
    x1 = contexts.get(0).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_0(5.0.0):c1", x1);
    x2 = contexts.get(1).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_1(5.0.0):c3/1:delGen=1", x2);
    x3 = contexts.get(2).reader().getCombinedCoreAndDeletesKey().toString();
    assertEquals("_2(5.0.0):c1", x3);
    ki.close();
}
Also used : Path(java.nio.file.Path) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory)

Example 84 with KrillIndex

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

the class TestIndexRevision method testIndexRevisionTempFile.

@Test
public void testIndexRevisionTempFile() throws IOException {
    Path tmpdir = Files.createTempDirectory("wiki");
    KrillIndex ki = new KrillIndex(new MMapDirectory(tmpdir));
    assertEquals("null", ki.getFingerprint());
    ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
    ki.commit();
    ki.addDoc(getClass().getResourceAsStream("/wiki/00002.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00003.json.gz"), true);
    ki.addDoc(getClass().getResourceAsStream("/wiki/00004.json.gz"), true);
    ki.commit();
    ki.addDoc(getClass().getResourceAsStream("/wiki/00006.json.gz"), true);
    ki.commit();
    assertTrue(ki.delDocs("title", "A"));
    ki.commit();
    assertEquals(false, ki.isReaderOpen());
    String fingerp = "aoD2zQvZKa8oQPjFJlji1g==";
    assertEquals(fingerp, ki.getFingerprint());
    assertEquals(true, ki.isReaderOpen());
    assertEquals(4, ki.numberOf("base", "documents"));
    assertEquals(fingerp, ki.getFingerprint());
    ki.close();
    // Reload index
    ki = new KrillIndex(new MMapDirectory(tmpdir));
    assertEquals(fingerp, ki.getFingerprint());
    ki.close();
}
Also used : Path(java.nio.file.Path) KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory) Test(org.junit.Test)

Example 85 with KrillIndex

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

the class TestIndexRevision method testIndexRevisionSample.

@Ignore
public void testIndexRevisionSample() throws IOException {
    KrillIndex ki = new KrillIndex(new MMapDirectory(Paths.get(getClass().getResource("/sample-index").getFile())));
    assertEquals("Wes8Bd4h1OypPqbWF5njeQ==", ki.getFingerprint());
}
Also used : KrillIndex(de.ids_mannheim.korap.KrillIndex) MMapDirectory(org.apache.lucene.store.MMapDirectory) Ignore(org.junit.Ignore)

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