Skip to content

Commit

Permalink
Handle synonyms in ES score debug
Browse files Browse the repository at this point in the history
kwahlin committed Jan 28, 2025

Verified

This commit was signed with the committer’s verified signature.
sandhose Quentin Gliech
1 parent 49596c4 commit b8a1cdc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions whelk-core/src/main/groovy/whelk/search2/QueryResult.java
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -187,9 +188,26 @@ private static Map<String, Double> getScorePerField(Map<String, Object> scoreExp
}

private static String parseField(String description) {
Matcher m = Pattern.compile("^weight\\(.+:((\".+\")|[^ ]+)").matcher(description);
if (m.find()) {
return m.group().replace("weight(", "");
if (description.startsWith("weight(")) {
description = description.replace("weight(", "");
if (description.startsWith("Synonym(")) {
description = description.replace("Synonym(", "");
Matcher matcher = Pattern.compile("^[^ ]+:[^ ]+( [^ ]+:[^ )]+)+").matcher(description);
if (matcher.find()) {
String match = matcher.group();
String key = match.substring(0, match.indexOf(":"));
String values = Arrays.stream(match.split(" "))
.map(s -> s.split(":"))
.map(s -> s[1])
.collect(Collectors.joining(" "));
return key + ":(" + values + ")";
}
} else {
Matcher m = Pattern.compile("^[^ ]+:((\".+\")|[^ ]+)").matcher(description);
if (m.find()) {
return m.group();
}
}
}
return description;
}

0 comments on commit b8a1cdc

Please sign in to comment.