Broken test for highlighting with distance queries
diff --git a/src/main/java/de/ids_mannheim/korap/KorapMatch.java b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
index 31ccd5d..30c15f0 100644
--- a/src/main/java/de/ids_mannheim/korap/KorapMatch.java
+++ b/src/main/java/de/ids_mannheim/korap/KorapMatch.java
@@ -755,6 +755,11 @@
pos = element[3] != 0 ? element[0] : element[1];
if (pos > oldPos) {
+
+ if (pos > clean.length() - 1) {
+ pos = clean.length() - 1;
+ };
+
snippetStack.addString(clean.substring(oldPos, pos));
oldPos = pos;
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
index f577738..7e4032b 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestFieldDocument.java
@@ -27,6 +27,10 @@
import de.ids_mannheim.korap.index.FieldDocument;
import de.ids_mannheim.korap.analysis.MultiTermTokenStream;
+import de.ids_mannheim.korap.query.wrap.SpanQueryWrapperInterface;
+
+import de.ids_mannheim.korap.util.QueryException;
+
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.index.Term;
@@ -219,6 +223,7 @@
assertNotNull(kr.toJSON());
+
/*
System.err.println(ki.getMatchInfo(
"match-WPD!WPD_AAA.00004-p200-206",
@@ -231,7 +236,55 @@
).toJSON());
*/
// ki.getMatch();
+ };
+ @Test
+ public void queryJSONBsp18 () throws IOException {
+ // Construct index
+ KorapIndex ki = new KorapIndex();
+
+ // Indexing test files
+ for (String i : new String[] {"00001", "00002", "00003", "00004", "00005", "00006", "02439"}) {
+ FieldDocument fd = ki.addDocFile(
+ getClass().getResource("/wiki/" + i + ".json.gz").getFile(), true
+ );
+ };
+ ki.commit();
+
+ SpanQueryWrapperInterface sqwi = jsonQuery(getClass().getResource("/queries/bsp18.jsonld").getFile());
+
+ KorapResult kr = ki.search(sqwi.toQuery(), 0, (short) 5, true, (short) 2, false, (short) 5);
+
+ // Bug: System.err.println(kr.toJSON());
+ };
+
+ public static String getString (String path) {
+ StringBuilder contentBuilder = new StringBuilder();
+ try {
+ BufferedReader in = new BufferedReader(new FileReader(path));
+ String str;
+ while ((str = in.readLine()) != null) {
+ contentBuilder.append(str);
+ };
+ in.close();
+ } catch (IOException e) {
+ fail(e.getMessage());
+ }
+ return contentBuilder.toString();
+ };
+
+ public static SpanQueryWrapperInterface jsonQuery (String jsonFile) {
+ SpanQueryWrapperInterface sqwi;
+
+ try {
+ String json = getString(jsonFile);
+ sqwi = new KorapQuery("tokens").fromJSON(json);
+ }
+ catch (QueryException e) {
+ fail(e.getMessage());
+ sqwi = new KorapQuery("tokens").seg("???");
+ };
+ return sqwi;
};
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
index 41fdd1f..c3c7443 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRealIndex.java
@@ -48,7 +48,6 @@
// This is real slow atm - sorry
kc.filter(kf.and("textClass", "kultur"));
- // kc.filter(kf.and("ID", "A00_JAN.02873"));
// Create a query
diff --git a/src/test/resources/queries/bsp18.jsonld b/src/test/resources/queries/bsp18.jsonld
new file mode 100644
index 0000000..99afb29
--- /dev/null
+++ b/src/test/resources/queries/bsp18.jsonld
@@ -0,0 +1,53 @@
+{
+ "context" : "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld",
+ "query" : {
+ "@type" : "korap:group",
+ "operation" : "operation:sequence",
+ "inOrder" : true,
+ "distances" : [ {
+ "@type" : "korap:distance",
+ "key" : "w",
+ "min" : 0,
+ "max" : 5
+ } ],
+ "operands" : [ {
+ "@type" : "korap:group",
+ "operation" : "operation:class",
+ "class" : 1,
+ "operands" : [ {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "der",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ } ]
+ }, {
+ "@type" : "korap:token",
+ "wrap" : {
+ "@type" : "korap:term",
+ "key" : "nicht",
+ "layer" : "orth",
+ "match" : "match:eq"
+ }
+ } ]
+ },
+ "collections" : [ {
+ "@type" : "korap:meta-filter",
+ "@value" : {
+ "@type" : "korap:term",
+ "@field" : "korap:field#corpusID",
+ "@value" : "WPD"
+ }
+ } ],
+ "meta" : {
+ "context" : {
+ "left" : [ "char", 110 ],
+ "right" : [ "char", 110 ]
+ },
+ "cutOff" : true,
+ "startPage" : 1,
+ "count" : 25
+ }
+}
\ No newline at end of file