diff options
author | Arne H Juul <arnej@yahooinc.com> | 2021-11-08 08:37:38 +0000 |
---|---|---|
committer | Arne H Juul <arnej@yahooinc.com> | 2021-11-08 08:37:42 +0000 |
commit | a95f1a9033545e08e21a2d656f84fd2d4f2293d4 (patch) | |
tree | e07a5c14e48127a3c8aee5f854dc9c882890f28a | |
parent | a6aede7c79dcda9bee20174296b9673d9e0b32b1 (diff) |
let match-features inherit also
* a rank-profile can now inherit its parent's match-features and
add its own, exactly the same way as summary-features.
5 files changed, 50 insertions, 1 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java index b5d86f5bb38..7b30e81badb 100644 --- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java +++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java @@ -98,6 +98,8 @@ public class RankProfile implements Cloneable { private String inheritedSummaryFeatures; private Set<ReferenceNode> matchFeatures; + private String inheritedMatchFeatures; + private Set<ReferenceNode> rankFeatures; /** The properties of this - a multimap */ @@ -519,8 +521,30 @@ public class RankProfile implements Cloneable { this.inheritedSummaryFeatures = parentProfile; } + /** + * Sets the name of a profile this should inherit the match features of. + * Without setting this, this will either have the match features of the parent, + * or if match features are set in this, only have the match features in this. + * With this set the resulting match features of this will be the superset of those defined in this and + * the final (with inheritance included) summary features of the given parent. + * The profile must be the profile which is directly inherited by this. + * + */ + public void setInheritedMatchFeatures(String parentProfile) { + if ( ! parentProfile.equals(inheritedName)) + throw new IllegalArgumentException("This rank profile ("+name+") can only inherit the match features of its parent, '" + + inheritedName + ", but attemtping to inherit '" + parentProfile); + this.inheritedMatchFeatures = parentProfile; + } + /** Returns a read-only view of the match features to use in this profile. This is never null */ public Set<ReferenceNode> getMatchFeatures() { + if (inheritedMatchFeatures != null && matchFeatures != null) { + Set<ReferenceNode> combined = new HashSet<>(); + combined.addAll(getInherited().getMatchFeatures()); + combined.addAll(matchFeatures); + return Collections.unmodifiableSet(combined); + } if (matchFeatures != null) return Collections.unmodifiableSet(matchFeatures); if (getInherited() != null) return getInherited().getMatchFeatures(); return Set.of(); diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj index 5bcc033fa37..07171dea803 100644 --- a/config-model/src/main/javacc/SDParser.jj +++ b/config-model/src/main/javacc/SDParser.jj @@ -358,6 +358,7 @@ TOKEN : | < MULTITHREADEDINDEXING: "multi-threaded-indexing" > | < MATCHFEATURES_SL: "match-features" (" ")* ":" (~["}","\n"])* ("\n")? > | < MATCHFEATURES_ML: "match-features" (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" > +| < MATCHFEATURES_ML_INHERITS: "match-features inherits " (<IDENTIFIER>) (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" > | < SUMMARYFEATURES_SL: "summary-features" (" ")* ":" (~["}","\n"])* ("\n")? > | < SUMMARYFEATURES_ML: "summary-features" (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" > | < SUMMARYFEATURES_ML_INHERITS: "summary-features inherits " (<IDENTIFIER>) (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" > @@ -2322,7 +2323,14 @@ Object matchFeatures(RankProfile profile) : { ( <MATCHFEATURES_SL> { features = token.image.substring(token.image.indexOf(":") + 1).trim(); } | <MATCHFEATURES_ML> { features = token.image.substring(token.image.indexOf("{") + 1, - token.image.lastIndexOf("}")).trim(); } ) + token.image.lastIndexOf("}")).trim(); } | + <MATCHFEATURES_ML_INHERITS> { + int inheritsIndex = token.image.indexOf("inherits "); + String rest = token.image.substring(inheritsIndex + "inherits ".length()); + profile.setInheritedMatchFeatures(rest.substring(0, rest.indexOf(" ")).trim()); + features = token.image.substring(token.image.indexOf("{") + 1, token.image.lastIndexOf("}")).trim(); + } + ) { profile.addMatchFeatures(getFeatureList(features)); return null; diff --git a/config-model/src/test/derived/rankprofileinheritance/child.sd b/config-model/src/test/derived/rankprofileinheritance/child.sd index 9369472cb23..a6e0787a659 100644 --- a/config-model/src/test/derived/rankprofileinheritance/child.sd +++ b/config-model/src/test/derived/rankprofileinheritance/child.sd @@ -20,6 +20,10 @@ schema child { attribute(field3) } + match-features inherits profile1 { + function3 + } + } rank-profile profile4 inherits profile2 { diff --git a/config-model/src/test/derived/rankprofileinheritance/parent1.sd b/config-model/src/test/derived/rankprofileinheritance/parent1.sd index d4375427e11..d25182fde4c 100644 --- a/config-model/src/test/derived/rankprofileinheritance/parent1.sd +++ b/config-model/src/test/derived/rankprofileinheritance/parent1.sd @@ -15,11 +15,18 @@ schema parent1 { expression: attribute(field1) + 5 } + function function1b() { + expression: attribute(field1) + 42 + } + summary-features { function1 attribute(field1) } + match-features { + function1b + } } } diff --git a/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg b/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg index 88788f5a93a..440b0ad2b97 100644 --- a/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg +++ b/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg @@ -11,12 +11,18 @@ rankprofile[].fef.property[].value "true" rankprofile[].name "profile3" rankprofile[].fef.property[].name "rankingExpression(function3).rankingScript" rankprofile[].fef.property[].value "attribute(field3) + 5" +rankprofile[].fef.property[].name "rankingExpression(function1b).rankingScript" +rankprofile[].fef.property[].value "attribute(field1) + 42" rankprofile[].fef.property[].name "rankingExpression(function1).rankingScript" rankprofile[].fef.property[].value "attribute(field1) + 5" rankprofile[].fef.property[].name "vespa.summary.feature" rankprofile[].fef.property[].value "attribute(field3)" rankprofile[].fef.property[].name "vespa.summary.feature" rankprofile[].fef.property[].value "rankingExpression(function3)" +rankprofile[].fef.property[].name "vespa.match.feature" +rankprofile[].fef.property[].value "rankingExpression(function3)" +rankprofile[].fef.property[].name "vespa.match.feature" +rankprofile[].fef.property[].value "rankingExpression(function1b)" rankprofile[].name "profile4" rankprofile[].fef.property[].name "rankingExpression(function2).rankingScript" rankprofile[].fef.property[].value "attribute(field2) + 5" |