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());
}
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());
}
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();
}
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();
}
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());
}
Aggregations