summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-06-02 08:44:21 +0200
committerJon Bratseth <bratseth@gmail.com>2020-06-02 08:44:21 +0200
commitac03f1b821c15062986c6542d248b19c66a17db9 (patch)
treed22523a69073f8d747ac09b614cd88f0ec117106 /config-model
parent2e3d463d90a4834b65446415e1f92389091716ab (diff)
Explicitly inherit summary features
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java32
-rw-r--r--config-model/src/main/javacc/SDParser.jj18
-rw-r--r--config-model/src/test/derived/rankprofileinheritance/child.sd37
-rw-r--r--config-model/src/test/derived/rankprofileinheritance/parent1.sd24
-rw-r--r--config-model/src/test/derived/rankprofileinheritance/parent2.sd24
-rw-r--r--config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg32
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java5
7 files changed, 159 insertions, 13 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 ea126123a25..8b2a190feb9 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/RankProfile.java
@@ -91,6 +91,7 @@ public class RankProfile implements Cloneable {
private double rankScoreDropLimit = -Double.MAX_VALUE;
private Set<ReferenceNode> summaryFeatures;
+ private String inheritedSummaryFeatures;
private Set<ReferenceNode> rankFeatures;
@@ -386,9 +387,15 @@ public class RankProfile implements Cloneable {
/** Returns a read-only view of the summary features to use in this profile. This is never null */
public Set<ReferenceNode> getSummaryFeatures() {
+ if (inheritedSummaryFeatures != null && summaryFeatures != null) {
+ Set<ReferenceNode> combined = new HashSet<>();
+ combined.addAll(getInherited().getSummaryFeatures());
+ combined.addAll(summaryFeatures);
+ return Collections.unmodifiableSet(combined);
+ }
if (summaryFeatures != null) return Collections.unmodifiableSet(summaryFeatures);
if (getInherited() != null) return getInherited().getSummaryFeatures();
- return Collections.emptySet();
+ return Set.of();
}
private void addSummaryFeature(ReferenceNode feature) {
@@ -397,17 +404,30 @@ public class RankProfile implements Cloneable {
summaryFeatures.add(feature);
}
- /**
- * Adds the content of the given feature list to the internal list of summary features.
- *
- * @param features The features to add.
- */
+ /** Adds the content of the given feature list to the internal list of summary features. */
public void addSummaryFeatures(FeatureList features) {
for (ReferenceNode feature : features) {
addSummaryFeature(feature);
}
}
+ /**
+ * Sets the name this should inherit the summary features of.
+ * Without setting this, this will either have the summary features of the parent,
+ * or if summary features are set in this, only have the summary features in this.
+ * With this set the resulting summary 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.
+ *
+ * @param parentProfile
+ */
+ public void setInheritedSummaryFeatures(String parentProfile) {
+ if ( ! parentProfile.equals(inheritedName))
+ throw new IllegalArgumentException("This can only inherit the summary features of its parent, '" +
+ inheritedName + ", but attemtping to inherit '" + parentProfile);
+ this.inheritedSummaryFeatures = parentProfile;
+ }
+
/** Returns a read-only view of the rank features to use in this profile. This is never null */
public Set<ReferenceNode> getRankFeatures() {
if (rankFeatures != null) return Collections.unmodifiableSet(rankFeatures);
diff --git a/config-model/src/main/javacc/SDParser.jj b/config-model/src/main/javacc/SDParser.jj
index 043599dedbf..5586b6a24e7 100644
--- a/config-model/src/main/javacc/SDParser.jj
+++ b/config-model/src/main/javacc/SDParser.jj
@@ -339,6 +339,7 @@ TOKEN :
| < NEIGHBORSTOEXPLOREATINSERT: "neighbors-to-explore-at-insert" >
| < SUMMARYFEATURES_SL: "summary-features" (" ")* ":" (~["}","\n"])* ("\n")? >
| < SUMMARYFEATURES_ML: "summary-features" (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" >
+| < SUMMARYFEATURES_ML_INHERITS: "summary-features inherits " (<IDENTIFIER>) (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" >
| < RANKFEATURES_SL: "rank-features" (" ")* ":" (~["}","\n"])* ("\n")? >
| < RANKFEATURES_ML: "rank-features" (<SEARCHLIB_SKIP>)? "{" (~["}"])* "}" >
| < EXPRESSION_SL: "expression" (" ")* ":" (("{"<BRACE_SL_LEVEL_1>)|<BRACE_SL_CONTENT>)* ("\n")? >
@@ -2144,23 +2145,26 @@ Object secondPhaseItem(RankProfile profile) :
Object summaryFeatures(RankProfile profile) :
{
String features;
+ String inherited = null;
}
{
( <SUMMARYFEATURES_SL> { features = token.image.substring(token.image.indexOf(":") + 1).trim(); } |
<SUMMARYFEATURES_ML> { features = token.image.substring(token.image.indexOf("{") + 1,
- token.image.lastIndexOf("}")).trim(); } )
+ token.image.lastIndexOf("}")).trim(); } |
+ <SUMMARYFEATURES_ML_INHERITS> {
+ int inheritsIndex = token.image.indexOf("inherits ");
+ String rest = token.image.substring(inheritsIndex + "inherits ".length());
+ profile.setInheritedSummaryFeatures(rest.substring(0, rest.indexOf(" ")).trim());
+ features = token.image.substring(token.image.indexOf("{") + 1, token.image.lastIndexOf("}")).trim();
+ }
+ )
{
profile.addSummaryFeatures(getFeatureList(features));
return null;
}
}
-/**
- * This rule consumes a rank-features block of a rank profile.
- *
- * @param profile The rank profile to modify.
- * @return Null.
- */
+/** Consumes a rank-features block of a rank profile */
Object rankFeatures(RankProfile profile) :
{
String features;
diff --git a/config-model/src/test/derived/rankprofileinheritance/child.sd b/config-model/src/test/derived/rankprofileinheritance/child.sd
new file mode 100644
index 00000000000..f76aa3a1f10
--- /dev/null
+++ b/config-model/src/test/derived/rankprofileinheritance/child.sd
@@ -0,0 +1,37 @@
+schema child {
+
+ document child inherits parent1, parent2 {
+
+ field field3 type int {
+ indexing: attribute
+ }
+
+ }
+
+ rank-profile profile3 inherits profile1 {
+
+ function function3() {
+ expression: attribute(field3) + 5
+ }
+
+ summary-features {
+ function3
+ attribute(field3)
+ }
+
+ }
+
+ rank-profile profile4 inherits profile2 {
+
+ function function4() {
+ expression: attribute(field3) + 5
+ }
+
+ summary-features inherits profile2 {
+ function4
+ attribute(field3)
+ }
+
+ }
+
+} \ No newline at end of file
diff --git a/config-model/src/test/derived/rankprofileinheritance/parent1.sd b/config-model/src/test/derived/rankprofileinheritance/parent1.sd
new file mode 100644
index 00000000000..ea11ffbc82e
--- /dev/null
+++ b/config-model/src/test/derived/rankprofileinheritance/parent1.sd
@@ -0,0 +1,24 @@
+schema parent1 {
+
+ document parent1 {
+
+ field field1 type int {
+ indexing: attribute
+ }
+
+ }
+
+ rank-profile profile1 {
+
+ function function1() {
+ expression: attribute(field1) + 5
+ }
+
+ summary-features {
+ function1
+ attribute(field1)
+ }
+
+ }
+
+}
diff --git a/config-model/src/test/derived/rankprofileinheritance/parent2.sd b/config-model/src/test/derived/rankprofileinheritance/parent2.sd
new file mode 100644
index 00000000000..1246f7264b3
--- /dev/null
+++ b/config-model/src/test/derived/rankprofileinheritance/parent2.sd
@@ -0,0 +1,24 @@
+schema parent2 {
+
+ document parent2 {
+
+ field field2 type int {
+ indexing: attribute
+ }
+
+ }
+
+ rank-profile profile2 {
+
+ function function2() {
+ expression: attribute(field2) + 5
+ }
+
+ summary-features {
+ function2
+ attribute(field2)
+ }
+
+ }
+
+}
diff --git a/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg b/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg
new file mode 100644
index 00000000000..88788f5a93a
--- /dev/null
+++ b/config-model/src/test/derived/rankprofileinheritance/rank-profiles.cfg
@@ -0,0 +1,32 @@
+rankprofile[].name "default"
+rankprofile[].name "unranked"
+rankprofile[].fef.property[].name "vespa.rank.firstphase"
+rankprofile[].fef.property[].value "value(0)"
+rankprofile[].fef.property[].name "vespa.hitcollector.heapsize"
+rankprofile[].fef.property[].value "0"
+rankprofile[].fef.property[].name "vespa.hitcollector.arraysize"
+rankprofile[].fef.property[].value "0"
+rankprofile[].fef.property[].name "vespa.dump.ignoredefaultfeatures"
+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(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[].name "profile4"
+rankprofile[].fef.property[].name "rankingExpression(function2).rankingScript"
+rankprofile[].fef.property[].value "attribute(field2) + 5"
+rankprofile[].fef.property[].name "rankingExpression(function4).rankingScript"
+rankprofile[].fef.property[].value "attribute(field3) + 5"
+rankprofile[].fef.property[].name "vespa.summary.feature"
+rankprofile[].fef.property[].value "attribute(field2)"
+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(function2)"
+rankprofile[].fef.property[].name "vespa.summary.feature"
+rankprofile[].fef.property[].value "rankingExpression(function4)"
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
index 3c55aa808b5..71cca20f8fa 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/derived/ExportingTestCase.java
@@ -156,4 +156,9 @@ public class ExportingTestCase extends AbstractExportingTestCase {
assertCorrectDeriving("hnsw_index");
}
+ @Test
+ public void testRankProfileInheritance() throws IOException, ParseException {
+ assertCorrectDeriving("rankprofileinheritance", "child");
+ }
+
}