Make defaultSearchContextLength and maxCharContextSize customizable.
Change-Id: I24a35e0ffa0b7904e3e8df38d87015bcb831d43e
diff --git a/Changes b/Changes
index e72713d..e101056 100644
--- a/Changes
+++ b/Changes
@@ -1,6 +1,8 @@
-0.63.3 2024-09-24
+0.63.3 2024-11-04
- [performance] Improve short circuit on count=0 and
cutoff=true (diewald)
+ - [feature] Make defaultSearchContextLength and maxCharContextSize
+ customizable (margaretha)
0.63.2 2024-08-02
- [bugfix] Fix empty DocIdSetIterator (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/response/SearchContext.java b/src/main/java/de/ids_mannheim/korap/response/SearchContext.java
index 7deb78a..752dbd6 100644
--- a/src/main/java/de/ids_mannheim/korap/response/SearchContext.java
+++ b/src/main/java/de/ids_mannheim/korap/response/SearchContext.java
@@ -73,7 +73,7 @@
public class SearchContextSide {
private boolean isToken = true;
- private int length = 6;
+ private int length = KrillProperties.defaultSearchContextLength;
private int maxTokenLength = KrillProperties.maxTokenContextSize;
private int maxCharLength = KrillProperties.maxCharContextSize;
diff --git a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
index 6c6d5b4..6ed4dbc 100644
--- a/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
+++ b/src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
@@ -22,6 +22,7 @@
public static int maxTokenMatchSize = 50;
public static int maxTokenContextSize = 60;
public static int maxCharContextSize = 500;
+ public static int defaultSearchContextLength = 6;
public static boolean matchExpansionIncludeContextSize = false;
@@ -82,6 +83,9 @@
public static void updateConfigurations (Properties prop) {
String maxTokenMatchSize = prop.getProperty("krill.match.max.token");
String maxTokenContextSize = prop.getProperty("krill.context.max.token");
+ // EM: not implemented yet
+// String maxCharContextSize = prop.getProperty("krill.context.max.char");
+ String defaultSearchContextLength = prop.getProperty("krill.search.context.default");
try {
if (maxTokenMatchSize != null) {
@@ -92,6 +96,14 @@
KrillProperties.maxTokenContextSize = Integer
.parseInt(maxTokenContextSize);
}
+// if (maxCharContextSize != null) {
+// KrillProperties.maxCharContextSize = Integer
+// .parseInt(maxCharContextSize);
+// }
+ if (defaultSearchContextLength != null) {
+ KrillProperties.defaultSearchContextLength = Integer
+ .parseInt(defaultSearchContextLength);
+ }
}
catch (NumberFormatException e) {
log.error("A Krill property expects numerical values: "
diff --git a/src/test/java/de/ids_mannheim/korap/index/TestMaxContext.java b/src/test/java/de/ids_mannheim/korap/index/TestMaxContext.java
index 239d9eb..6072688 100644
--- a/src/test/java/de/ids_mannheim/korap/index/TestMaxContext.java
+++ b/src/test/java/de/ids_mannheim/korap/index/TestMaxContext.java
@@ -42,7 +42,7 @@
}
@Test
- public void testTokenContextSize () throws IOException {
+ public void testSmallerTokenContextSize () throws IOException {
assertEquals(25, KrillProperties.maxTokenContextSize);
@@ -61,7 +61,7 @@
assertEquals(5, km.getContext().left.getLength());
assertEquals(5, km.getContext().right.getLength());
};
-
+
@Test
public void searchWithLargerContextTokenSize ()
throws JsonMappingException, JsonProcessingException {
@@ -123,4 +123,19 @@
String rightContext = km.getSnippetBrackets().split("]]")[1];
assertEquals(KrillProperties.maxCharContextSize,rightContext.length() -4);
}
+
+ // for Kokokom
+ @Test
+ public void testIncreaseDefaultSearchContextSize () throws IOException {
+ KrillProperties.defaultSearchContextLength = 1000000000;
+
+ String jsonQuery = getJsonString(TestMaxContext.class
+ .getResource("/queries/flags/caseInsensitive.jsonld")
+ .getFile());
+ Krill ks = new Krill(jsonQuery);
+ Result kr = ks.apply(ki);
+ Match km = kr.getMatch(0);
+ assertEquals(6089, km.getSnippetBrackets().length());
+ KrillProperties.defaultSearchContextLength = 6;
+ };
}
diff --git a/src/test/resources/krill.properties b/src/test/resources/krill.properties
index fc26a13..5afab41 100644
--- a/src/test/resources/krill.properties
+++ b/src/test/resources/krill.properties
@@ -9,3 +9,4 @@
krill.match.expansion.includeContextSize = true
krill.match.max.token=50
krill.context.max.token=25
+krill.search.context.default=6
\ No newline at end of file
diff --git a/src/test/resources/queries/flags/caseInsensitive.jsonld b/src/test/resources/queries/flags/caseInsensitive.jsonld
index 7320f52..35f9f5e 100644
--- a/src/test/resources/queries/flags/caseInsensitive.jsonld
+++ b/src/test/resources/queries/flags/caseInsensitive.jsonld
@@ -18,6 +18,6 @@
"startPage":1,
"count":25,
"cutOff":true,
- "context":"paragraph"
+ "context":"text"
}
}