diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-05-11 11:31:14 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-05-11 12:34:35 +0000 |
commit | 47b370c90715a15939474951fbdb6fad987073e9 (patch) | |
tree | 1b8fc8756d2e9b5c9c38b7ee4ca8c82a3cd25e28 /config-model/src/main/java/com/yahoo/schema/RankProfile.java | |
parent | 5693b9621d9882f0e9a66c7d6441b898cb43f6d9 (diff) |
add filtering to hide implicitly added match features
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/RankProfile.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/schema/RankProfile.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/RankProfile.java b/config-model/src/main/java/com/yahoo/schema/RankProfile.java index 639930041c3..69f32daef4a 100644 --- a/config-model/src/main/java/com/yahoo/schema/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/schema/RankProfile.java @@ -108,6 +108,7 @@ public class RankProfile implements Cloneable { private String inheritedSummaryFeaturesProfileName; private Set<ReferenceNode> matchFeatures; + private Set<String> hiddenMatchFeatures; private String inheritedMatchFeaturesProfileName; private Set<ReferenceNode> rankFeatures; @@ -605,6 +606,12 @@ public class RankProfile implements Cloneable { .orElse(Set.of()); } + public Set<String> getHiddenMatchFeatures() { + if (hiddenMatchFeatures != null) return Collections.unmodifiableSet(hiddenMatchFeatures); + return uniquelyInherited(p -> p.getHiddenMatchFeatures(), f -> ! f.isEmpty(), "hidden match features") + .orElse(Set.of()); + } + private void addSummaryFeature(ReferenceNode feature) { if (summaryFeatures == null) summaryFeatures = new LinkedHashSet<>(); @@ -617,6 +624,21 @@ public class RankProfile implements Cloneable { matchFeatures.add(feature); } + private void addImplicitMatchFeatures(List<FeatureList> list) { + if (matchFeatures == null) + matchFeatures = new LinkedHashSet<>(); + if (hiddenMatchFeatures == null) + hiddenMatchFeatures = new LinkedHashSet<>(); + for (var features : list) { + for (ReferenceNode feature : features) { + if (! matchFeatures.contains(feature)) { + matchFeatures.add(feature); + hiddenMatchFeatures.add(feature.toString()); + } + } + } + } + /** Adds the content of the given feature list to the internal list of summary features. */ public void addSummaryFeatures(FeatureList features) { for (ReferenceNode feature : features) { @@ -1037,16 +1059,18 @@ public class RankProfile implements Cloneable { var needInputs = new HashSet<String>(); var recorder = new InputRecorder(needInputs); recorder.process(globalPhaseRanking.function().getBody(), context); + List<FeatureList> addIfMissing = new ArrayList<>(); for (String input : needInputs) { if (input.startsWith("constant(") || input.startsWith("query(")) { continue; } try { - addMatchFeatures(new FeatureList(input)); + addIfMissing.add(new FeatureList(input)); } catch (com.yahoo.searchlib.rankingexpression.parser.ParseException e) { throw new IllegalArgumentException("invalid input in global-phase expression: "+input); } } + addImplicitMatchFeatures(addIfMissing); } } @@ -1132,7 +1156,7 @@ public class RankProfile implements Cloneable { allImportedFields().forEach(field -> addAttributeFeatureTypes(field, featureTypes)); return featureTypes; } - + public MapEvaluationTypeContext typeContext(QueryProfileRegistry queryProfiles, Map<Reference, TensorType> featureTypes) { MapEvaluationTypeContext context = new MapEvaluationTypeContext(getExpressionFunctions(), featureTypes); |