diff --git a/whelk-core/src/main/groovy/whelk/search2/QueryResult.java b/whelk-core/src/main/groovy/whelk/search2/QueryResult.java index 46b5effb38..ccdb626786 100644 --- a/whelk-core/src/main/groovy/whelk/search2/QueryResult.java +++ b/whelk-core/src/main/groovy/whelk/search2/QueryResult.java @@ -17,6 +17,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; +import static whelk.JsonLd.SEARCH_KEY; import static whelk.search2.QueryUtil.castToStringObjectMap; import static whelk.util.DocumentUtil.getAtPath; import static whelk.util.DocumentUtil.traverse; @@ -81,7 +82,13 @@ private static Map normalizeResponse(Map esResponse) { return norm; } - private record EsItem(Map map) { + private class EsItem { + private final Map map; + + EsItem(Map map) { + this.map = map; + } + private Map toLd(Function, Map> applyLens) { LdItem ldItem = new LdItem(applyLens.apply(map)); @@ -90,7 +97,10 @@ private Map toLd(Function, Map reverseLinks) { map.put("reverseLinks", reverseLinks); } + @SuppressWarnings({"rawtypes", "unchecked"}) + private void addSearchStrings(EsItem esItem) { + DocumentUtil.traverse(esItem.map, (value, path) -> { + if (!path.isEmpty() && path.getLast().equals(SEARCH_KEY)) { + if (getAtPath(map, path.subList(0, path.size() - 1)) instanceof Map m) { + m.put(SEARCH_KEY, value); + } + } + return new DocumentUtil.Nop(); + }); + } + private void addScore(Map scoreExplanation) { var scorePerField = getScorePerField(scoreExplanation); var totalScore = scorePerField.values().stream().reduce((double) 0, Double::sum);