Fixed query bug for zero-boundary repetitions
Change-Id: I0cc638382e7b43a0899f30ab561abddc363dd6e8
diff --git a/misc/errorcodes.md b/misc/errorcodes.md
index b01ac08..1ef94c6 100644
--- a/misc/errorcodes.md
+++ b/misc/errorcodes.md
@@ -65,6 +65,7 @@
780: "This query matches everywhere"
781: "Optionality of query is ignored"
782: "Exclusivity of query is ignored"
+783: "This query can't match anywhere"
799: Unknown query serialization message (Arbitrary string)
```
diff --git a/src/main/java/de/ids_mannheim/korap/Krill.java b/src/main/java/de/ids_mannheim/korap/Krill.java
index af529d0..de55528 100644
--- a/src/main/java/de/ids_mannheim/korap/Krill.java
+++ b/src/main/java/de/ids_mannheim/korap/Krill.java
@@ -176,8 +176,12 @@
this.moveNotificationsFrom(kq);
// Throw an error, in case the query matches everywhere
- if (qw.isEmpty())
+ if (qw.isEmpty()) {
this.addError(780, "This query matches everywhere");
+ }
+ else if (qw.isNull()) {
+ this.addError(783, "This query can't match anywhere");
+ }
else {
diff --git a/src/main/java/de/ids_mannheim/korap/KrillQuery.java b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
index 3d70505..3185603 100644
--- a/src/main/java/de/ids_mannheim/korap/KrillQuery.java
+++ b/src/main/java/de/ids_mannheim/korap/KrillQuery.java
@@ -115,7 +115,7 @@
// Set max boundary
this.max = json.has("max") ? json.get("max").asInt(defaultMax)
: defaultMax;
-
+
if (DEBUG)
log.trace("Found koral:boundary with {}:{}", min, max);
};
@@ -723,12 +723,12 @@
// Check relation between min and max
if (min > max)
max = max;
-
+
SpanQueryWrapper sqw = this._fromKoral(operands.get(0));
if (sqw.maybeExtension())
return sqw.setMin(min).setMax(max);
-
+
return new SpanRepetitionQueryWrapper(sqw, min, max);
};
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
index 7549b83..cedb868 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestRepetitionIndex.java
@@ -204,7 +204,6 @@
// }
}
-
@Test
public void testCase5 () throws IOException {
ki = new KrillIndex();
@@ -240,5 +239,5 @@
System.out.println(km.getSnippetBrackets());
System.out.println(km.getStartPos() +","+km.getEndPos());
}*/
- }
+ };
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
index 9ee4bde..31a3612 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQueryJSON.java
@@ -587,8 +587,6 @@
};
};
-
-
public static String getString (String path) {
StringBuilder contentBuilder = new StringBuilder();
try {
diff --git a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
index f4c5b8e..1fb1f2b 100644
--- a/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
+++ b/src/test/java/de/ids_mannheim/korap/search/TestKrill.java
@@ -1128,6 +1128,22 @@
assertEquals(kr.getTotalResults(), 1);
};
+
+ @Test
+ public void queryJSONzeroRepetitionBug () throws IOException {
+ // der{0}
+ KrillIndex ki = new KrillIndex();
+ ki.addDoc(getClass().getResourceAsStream("/wiki/00001.json.gz"), true);
+ ki.commit();
+
+ String json = getString(getClass().getResource(
+ "/queries/bugs/zero_repetition_bug.jsonld").getFile());
+
+ Result kr = new Krill(json).apply(ki);
+
+ assertEquals(783, kr.getError(0).getCode());
+ assertEquals("This query can't match anywhere", kr.getError(0).getMessage());
+ };
/**
* This is a Schreibgebrauch ressource that didn't work for
diff --git a/src/test/resources/queries/bugs/zero_repetition_bug.jsonld b/src/test/resources/queries/bugs/zero_repetition_bug.jsonld
new file mode 100644
index 0000000..a1c9519
--- /dev/null
+++ b/src/test/resources/queries/bugs/zero_repetition_bug.jsonld
@@ -0,0 +1,31 @@
+{
+ "@context":"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld",
+ "query":{
+ "@type":"koral:group",
+ "operation":"operation:repetition",
+ "operands":[
+ {
+ "@type":"koral:token",
+ "wrap":{
+ "@type":"koral:term",
+ "layer":"orth",
+ "key":"der",
+ "match":"match:eq"
+ }
+ }
+ ],
+ "boundary":{
+ "@type":"koral:boundary",
+ "min":0,
+ "max":0
+ }
+ },
+ "meta":{
+ "startPage":1,
+ "count":25,
+ "context":{
+ "left":["t",40],
+ "right":["t",40]
+ }
+ }
+}
\ No newline at end of file