use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithDateRanges.
@Test
public void testIndexWithDateRanges() throws IOException {
ki = new KrillIndex();
ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
kcn.fromBuilder(cb.date("pubDate", "2005"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-10"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-16"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-07"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.since("pubDate", "2005-12-07"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.since("pubDate", "2005-12-10"));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.since("pubDate", "2005-12-16"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-16"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-10"));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-07"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-10").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-16").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-07").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.date("pubDate", "2005-12-09").not());
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-16").not());
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-15").not());
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-10").not());
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-09").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-07").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.till("pubDate", "2005-12-06").not());
assertEquals(3, kcn.docCount());
}
use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithCollectionBuilder.
@Test
public void testIndexWithCollectionBuilder() throws IOException {
ki = new KrillIndex();
ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
// Simple string tests
kcn.fromBuilder(cb.term("author", "Frank"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.term("author", "Peter"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.term("author", "Sebastian"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.term("author", "Michael"));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.term("nothing", "nothing"));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.term("textClass", "reisen"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.term("textClass", "kultur"));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.term("textClass", "finanzen"));
assertEquals(1, kcn.docCount());
// Simple orGroup tests
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Sebastian")));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Sebastian")).with(cb.term("author", "Peter")));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("author", "Huhu")).with(cb.term("author", "Haha")).with(cb.term("author", "Hehe")));
assertEquals(0, kcn.docCount());
// Multi field orGroup tests
kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Peter")));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Michael")));
assertEquals(1, kcn.docCount());
// Simple andGroup tests
kcn.fromBuilder(cb.andGroup().with(cb.term("author", "Frank")).with(cb.term("author", "Michael")));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.term("ID", "doc-1")).with(cb.term("author", "Frank")));
assertEquals(1, kcn.docCount());
// andGroup in keyword field test
kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "finanzen")));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "reisen")).with(cb.term("textClass", "kultur")));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.andGroup().with(cb.term("textClass", "finanzen")).with(cb.term("textClass", "kultur")));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.term("text", "mann"));
assertEquals(3, kcn.docCount());
kcn.fromBuilder(cb.term("text", "frau"));
assertEquals(1, kcn.docCount());
}
use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithNegation.
@Test
public void testIndexWithNegation() throws IOException {
ki = new KrillIndex();
ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
// Simple negation tests
kcn.fromBuilder(cb.term("author", "Frank").not());
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.term("textClass", "reisen").not());
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.term("textClass", "kultur").not());
assertEquals(1, kcn.docCount());
// orGroup with simple Negation
kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Peter")));
assertEquals(2, kcn.docCount());
kcn.fromBuilder(cb.orGroup().with(cb.term("textClass", "kultur").not()).with(cb.term("author", "Sebastian")));
assertEquals(1, kcn.docCount());
}
use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.
the class TestKrillCollectionIndex method testIndexWithRegexes.
@Test
public void testIndexWithRegexes() throws IOException {
ki = new KrillIndex();
FieldDocument fd = ki.addDoc(createDoc1());
ki.addDoc(createDoc2());
ki.addDoc(createDoc3());
ki.commit();
CollectionBuilder cb = new CollectionBuilder();
KrillCollection kcn = new KrillCollection(ki);
kcn.fromBuilder(cb.re("author", "Fran.*"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("author", "Blin.*"));
assertEquals(0, kcn.docCount());
kcn.fromBuilder(cb.re("author", "Frank|Peter"));
assertEquals(2, kcn.docCount());
// "Frau" requires text request!
kcn.fromBuilder(cb.text("text", "Frau"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.term("text", "frau"));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("text", "fra."));
assertEquals(1, kcn.docCount());
kcn.fromBuilder(cb.re("text", "fra.|ma.n"));
assertEquals(3, kcn.docCount());
String sv = fd.doc.getField("text").stringValue();
assertEquals("Der alte Mann ging über die Straße", sv);
kcn.fromBuilder(cb.term("text", sv));
assertEquals(1, kcn.docCount());
}
use of de.ids_mannheim.korap.collection.CollectionBuilder in project Krill by KorAP.
the class TestKrill method searchIndex.
@Test
public void searchIndex() throws IOException {
// Construct index
KrillIndex ki = new KrillIndex();
// Indexing test files
for (String i : new String[] { "00001", "00002", "00003", "00004", "00005", "00006", "02439" }) {
ki.addDoc(getClass().getResourceAsStream("/wiki/" + i + ".json.gz"), true);
}
;
ki.commit();
Krill ks = new Krill(new QueryBuilder("tokens").seg("s:Buchstaben"));
CollectionBuilder cb = new CollectionBuilder();
ks.getCollection().fromBuilder(cb.term("textClass", "reisen"));
KrillMeta meta = ks.getMeta();
meta.setCount(3);
meta.setStartIndex(5);
meta.getContext().left.setLength(1);
meta.getContext().right.setLength(1);
Result kr = ks.apply(ki);
assertEquals(kr.getTotalResults(), 6);
assertEquals(kr.getMatch(0).getSnippetBrackets(), "... dem [[Buchstaben]] A ...");
JsonNode res = ks.toJsonNode();
assertEquals(3, res.at("/meta/count").asInt());
assertEquals(5, res.at("/meta/startIndex").asInt());
assertEquals("token", res.at("/meta/context/left/0").asText());
assertEquals(1, res.at("/meta/context/left/1").asInt());
assertEquals("token", res.at("/meta/context/right/0").asText());
assertEquals(1, res.at("/meta/context/right/1").asInt());
}
Aggregations