Skip to content

Commit

Permalink
Merge "Make defaultSearchContextLength and maxCharContextSize customi…
Browse files Browse the repository at this point in the history
…zable."
  • Loading branch information
margaretha authored and Gerrit Code Review committed Dec 12, 2024
2 parents c14c78d + e8e9c10 commit 9a3903c
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Changes
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ else if (spanContext.equals("paragraph")) {

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;

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/ids_mannheim/korap/util/KrillProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class KrillProperties {
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;

Expand Down Expand Up @@ -82,6 +83,9 @@ public static Properties loadProperties (String propFile) {
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) {
Expand All @@ -92,6 +96,14 @@ public static void updateConfigurations (Properties prop) {
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: "
Expand Down
19 changes: 17 additions & 2 deletions src/test/java/de/ids_mannheim/korap/index/TestMaxContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static void init () throws IOException {
}

@Test
public void testTokenContextSize () throws IOException {
public void testSmallerTokenContextSize () throws IOException {

assertEquals(25, KrillProperties.maxTokenContextSize);

Expand All @@ -61,7 +61,7 @@ public void testTokenContextSize () throws IOException {
assertEquals(5, km.getContext().left.getLength());
assertEquals(5, km.getContext().right.getLength());
};

@Test
public void searchWithLargerContextTokenSize ()
throws JsonMappingException, JsonProcessingException {
Expand Down Expand Up @@ -123,4 +123,19 @@ public void searchWithLargerContextCharSize ()
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;
};
}
1 change: 1 addition & 0 deletions src/test/resources/krill.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ krill.test = true
krill.match.expansion.includeContextSize = true
krill.match.max.token=50
krill.context.max.token=25
krill.search.context.default=6
2 changes: 1 addition & 1 deletion src/test/resources/queries/flags/caseInsensitive.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"startPage":1,
"count":25,
"cutOff":true,
"context":"paragraph"
"context":"text"
}
}

0 comments on commit 9a3903c

Please sign in to comment.