Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions librisxl-tools/elasticsearch/libris_search_boost.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,27 @@
"value": "VirtualRecord",
"score": 1000
}
],
"source_excludes": [
"@reverse.instanceOf.@reverse.itemOf.hasComponent",
"@reverse.instanceOf.@reverse.itemOf.itemOf",
"@reverse.instanceOf.@reverse.itemOf.librissearch:itemNote",
"@reverse.instanceOf.@reverse.itemOf.librissearch:shelf",
"@reverse.instanceOf.@reverse.itemOf.meta",
"@reverse.instanceOf.@reverse.itemOf.sameAs",
"@reverse.instanceOf.@reverse.itemOf.shelfControlNumber",
"@reverse.instanceOf.@reverse.itemOf.shelfMark",
"@reverse.instanceOf.@reverse.itemOf.subject",
"@reverse.instanceOf.@reverse.itemOf.summary",
"@reverse.itemOf.hasComponent",
"@reverse.itemOf.itemOf",
"@reverse.itemOf.librissearch:itemNote",
"@reverse.itemOf.librissearch:shelf",
"@reverse.itemOf.meta",
"@reverse.itemOf.sameAs",
"@reverse.itemOf.shelfControlNumber",
"@reverse.itemOf.shelfMark",
"@reverse.itemOf.subject",
"@reverse.itemOf.summary"
]
}
29 changes: 21 additions & 8 deletions whelk-core/src/main/groovy/whelk/search2/ESSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -19,6 +20,7 @@ public class ESSettings {

private EsMappings mappings;
private final Boost boost;
private final List<String> sourceExcludes;

private int maxItems;

Expand All @@ -28,6 +30,7 @@ public ESSettings(Whelk whelk) {
this.maxItems = whelk.elastic.maxResultWindow;
}
this.boost = loadBoostSettings();
this.sourceExcludes = loadSourceExcludesSettings();
}

// For test only
Expand All @@ -43,6 +46,7 @@ private ESSettings(EsMappings mappings, Boost boost, int maxItems) {
this.mappings = mappings;
this.boost = boost;
this.maxItems = maxItems;
this.sourceExcludes = Collections.emptyList();
}

public boolean isConfigured() {
Expand All @@ -57,6 +61,10 @@ public Boost boost() {
return boost;
}

public List<String> sourceExcludes() {
return sourceExcludes;
}

public int maxItems() {
return maxItems;
}
Expand All @@ -66,6 +74,11 @@ public Boost loadBoostSettings() {
return new Boost(settings);
}

private List<String> loadSourceExcludesSettings() {
Map<?, ?> settings = toMap(Boost.class.getClassLoader().getResourceAsStream(BOOST_SETTINGS_FILE));
return getAsStream(settings, "source_excludes").map(String.class::cast).toList();
}

public static Boost loadBoostSettings(String json) {
return new Boost(toMap(json));
}
Expand Down Expand Up @@ -226,22 +239,22 @@ private static ConstantScore load(Map<?, ?> settings) {
}
}

private static Stream<?> getAsStream(Map<?, ?> m, String k) {
return getOrDefault(m, k, List.of()).stream();
}

private static Map<String, Object> getAsMap(Map<?, ?> m, String k) {
return getOrDefault(m, k, Map.of());
}

private static float getAsFloat(Map<?, ?> m, String k) {
return ((Number) m.get(k)).floatValue();
}
}

@SuppressWarnings("unchecked")
private static <T> T getOrDefault(Map<?, ?> m, String k, T defaultTo) {
return m.containsKey(k) ? (T) m.get(k) : defaultTo;
}
private static Stream<?> getAsStream(Map<?, ?> m, String k) {
return getOrDefault(m, k, List.of()).stream();
}

@SuppressWarnings("unchecked")
private static <T> T getOrDefault(Map<?, ?> m, String k, T defaultTo) {
return m.containsKey(k) ? (T) m.get(k) : defaultTo;
}

private static Map<?, ?> toMap(Object json) {
Expand Down
5 changes: 5 additions & 0 deletions whelk-core/src/main/groovy/whelk/search2/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ protected EsQuery doGetEsQuery() {
EsQueryTree esQueryTree = new EsQueryTree(expandedQueryTree, currentEsSettings, getSelectedFacets());
var esQueryDsl = buildEsQueryDsl(esQueryTree.getMainQuery(), esQueryTree.getPostFilter());
esQueryDsl.put("aggs", getEsAggQuery(getFullQueryTree().getRdfSubjectTypesList()));

return new EsQuery(esQueryDsl, indexNames);
}

Expand Down Expand Up @@ -268,6 +269,10 @@ private Map<String, Object> buildEsQueryDsl(Map<String, Object> mainQuery, Map<S
queryDsl.put("fields", List.of("*"));
}

if (!esSettings.sourceExcludes().isEmpty()) {
queryDsl.put("_source", Map.of("excludes", esSettings.sourceExcludes()));
}

return queryDsl;
}

Expand Down
Loading