From b8a1cdcd6eb47d704b00a7278389f8b313507488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kalle=20W=C3=A5hlin?= Date: Tue, 28 Jan 2025 10:21:03 +0100 Subject: [PATCH] Handle synonyms in ES score debug --- .../groovy/whelk/search2/QueryResult.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/whelk-core/src/main/groovy/whelk/search2/QueryResult.java b/whelk-core/src/main/groovy/whelk/search2/QueryResult.java index ccdb626786..28106b46ae 100644 --- a/whelk-core/src/main/groovy/whelk/search2/QueryResult.java +++ b/whelk-core/src/main/groovy/whelk/search2/QueryResult.java @@ -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 getScorePerField(Map 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; }