Added opt() method to QueryBuilder
Change-Id: I9033fc0b8d1a5c0ebac4468d66c8e381d8c3fbb3
diff --git a/Changes b/Changes
index aa15d42..4bc1f21 100644
--- a/Changes
+++ b/Changes
@@ -13,6 +13,7 @@
korap.index.TestNextIndex.testNextExpansionBug() (margaretha)
- [bugfix] Fixed left expansion match order (margaretha)
- [bugfix] Fixed right expansion match order & expansion over start (margaretha)
+ - [feature] Added opt() method to QueryBuilder (diewald)
0.58.0 2018-09-03
- [feature] Implemented referencing cached collection (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/query/QueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/QueryBuilder.java
index da433ba..761ddd9 100644
--- a/src/main/java/de/ids_mannheim/korap/query/QueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/QueryBuilder.java
@@ -455,4 +455,9 @@
int max) {
return new SpanRepetitionQueryWrapper(element, min, max);
};
+
+ // Optionality
+ public SpanRepetitionQueryWrapper opt (SpanQueryWrapper element) {
+ return new SpanRepetitionQueryWrapper(element, 0, 1);
+ };
};
diff --git a/src/test/java/de/ids_mannheim/korap/query/TestKrillQuery.java b/src/test/java/de/ids_mannheim/korap/query/TestKrillQuery.java
index cb4c5b6..af6b568 100644
--- a/src/test/java/de/ids_mannheim/korap/query/TestKrillQuery.java
+++ b/src/test/java/de/ids_mannheim/korap/query/TestKrillQuery.java
@@ -311,6 +311,14 @@
sq.toString());
};
+ @Test
+ public void KorapOptQuery () throws QueryException {
+ QueryBuilder kq = new QueryBuilder("field");
+ SpanQuery sq = kq.seq(kq.opt(kq.seg("x"))).append(kq.seg("y")).toQuery();
+ assertEquals(
+ "spanOr([field:y, spanNext(field:x, field:y)])",
+ sq.toString());
+ };
@Test