aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeir Storli <geirst@vespa.ai>2024-06-06 16:52:35 +0200
committerGitHub <noreply@github.com>2024-06-06 16:52:35 +0200
commit5d79fac0180017450bf34dc85087e4099cc86b9b (patch)
tree4f0df9df4c62f9d4747849fd8e56867905b5a9ee
parent8246c9b3761fe5c346963cc01d6669f6bd4197d9 (diff)
parent9d6e820f60b53b1422cf432ed22eab5d640fa894 (diff)
Merge pull request #31469 from vespa-engine/toregge/add-second-phase-rank-score-drop-limit-query-parameter
Add ranking.secondPhase.rankScoreDropLimit query parameter.
-rw-r--r--container-search/abi-spec.json23
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/Ranking.java9
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java1
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/SecondPhase.java73
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java10
5 files changed, 116 insertions, 0 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index d16a98c3750..4a39068dcd1 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -5502,6 +5502,7 @@
"public void setUseSignificance(boolean)",
"public boolean getUseSignificance()",
"public com.yahoo.search.query.ranking.MatchPhase getMatchPhase()",
+ "public com.yahoo.search.query.ranking.SecondPhase getSecondPhase()",
"public com.yahoo.search.query.ranking.GlobalPhase getGlobalPhase()",
"public com.yahoo.search.query.ranking.Matching getMatching()",
"public com.yahoo.search.query.ranking.SoftTimeout getSoftTimeout()",
@@ -5530,6 +5531,7 @@
"public static final java.lang.String KEEPRANKCOUNT",
"public static final java.lang.String RANKSCOREDROPLIMIT",
"public static final java.lang.String MATCH_PHASE",
+ "public static final java.lang.String SECOND_PHASE",
"public static final java.lang.String GLOBAL_PHASE",
"public static final java.lang.String DIVERSITY",
"public static final java.lang.String SOFTTIMEOUT",
@@ -7157,6 +7159,27 @@
],
"fields" : [ ]
},
+ "com.yahoo.search.query.ranking.SecondPhase" : {
+ "superClass" : "java.lang.Object",
+ "interfaces" : [
+ "java.lang.Cloneable"
+ ],
+ "attributes" : [
+ "public"
+ ],
+ "methods" : [
+ "public void <init>()",
+ "public static com.yahoo.search.query.profile.types.QueryProfileType getArgumentType()",
+ "public void setRankScoreDropLimit(double)",
+ "public java.lang.Double getRankScoreDropLimit()",
+ "public void prepare(com.yahoo.search.query.ranking.RankProperties)",
+ "public int hashCode()",
+ "public boolean equals(java.lang.Object)",
+ "public com.yahoo.search.query.ranking.SecondPhase clone()",
+ "public bridge synthetic java.lang.Object clone()"
+ ],
+ "fields" : [ ]
+ },
"com.yahoo.search.query.ranking.SoftTimeout" : {
"superClass" : "java.lang.Object",
"interfaces" : [
diff --git a/container-search/src/main/java/com/yahoo/search/query/Ranking.java b/container-search/src/main/java/com/yahoo/search/query/Ranking.java
index 09de1a24ef9..a559846d5fe 100644
--- a/container-search/src/main/java/com/yahoo/search/query/Ranking.java
+++ b/container-search/src/main/java/com/yahoo/search/query/Ranking.java
@@ -14,6 +14,7 @@ import com.yahoo.search.query.ranking.MatchPhase;
import com.yahoo.search.query.ranking.Matching;
import com.yahoo.search.query.ranking.RankFeatures;
import com.yahoo.search.query.ranking.RankProperties;
+import com.yahoo.search.query.ranking.SecondPhase;
import com.yahoo.search.query.ranking.SoftTimeout;
import com.yahoo.search.result.ErrorMessage;
@@ -45,6 +46,7 @@ public class Ranking implements Cloneable {
public static final String KEEPRANKCOUNT = "keepRankCount";
public static final String RANKSCOREDROPLIMIT = "rankScoreDropLimit";
public static final String MATCH_PHASE = "matchPhase";
+ public static final String SECOND_PHASE = "secondPhase";
public static final String GLOBAL_PHASE = "globalPhase";
public static final String DIVERSITY = "diversity";
public static final String SOFTTIMEOUT = "softtimeout";
@@ -69,6 +71,7 @@ public class Ranking implements Cloneable {
argumentType.addField(new FieldDescription(RANKSCOREDROPLIMIT, "double"));
argumentType.addField(new FieldDescription(GLOBAL_PHASE, new QueryProfileFieldType(GlobalPhase.getArgumentType())));
argumentType.addField(new FieldDescription(MATCH_PHASE, new QueryProfileFieldType(MatchPhase.getArgumentType()), "matchPhase"));
+ argumentType.addField(new FieldDescription(SECOND_PHASE, new QueryProfileFieldType(SecondPhase.getArgumentType())));
argumentType.addField(new FieldDescription(DIVERSITY, new QueryProfileFieldType(Diversity.getArgumentType())));
argumentType.addField(new FieldDescription(SOFTTIMEOUT, new QueryProfileFieldType(SoftTimeout.getArgumentType())));
argumentType.addField(new FieldDescription(MATCHING, new QueryProfileFieldType(Matching.getArgumentType())));
@@ -107,6 +110,8 @@ public class Ranking implements Cloneable {
private MatchPhase matchPhase = new MatchPhase();
+ private SecondPhase secondPhase = new SecondPhase();
+
private GlobalPhase globalPhase = new GlobalPhase();
private Matching matching = new Matching();
@@ -230,6 +235,9 @@ public class Ranking implements Cloneable {
/** Returns the match phase rank settings of this. This is never null. */
public MatchPhase getMatchPhase() { return matchPhase; }
+ /** Return the second-phase rank settings of this. This is never null. */
+ public SecondPhase getSecondPhase() { return secondPhase; }
+
/** Returns the global-phase rank settings of this. This is never null. */
public GlobalPhase getGlobalPhase() { return globalPhase; }
@@ -266,6 +274,7 @@ public class Ranking implements Cloneable {
public void prepare() {
rankFeatures.prepare(rankProperties);
matchPhase.prepare(rankProperties);
+ secondPhase.prepare(rankProperties);
matching.prepare(rankProperties);
softTimeout.prepare(rankProperties);
prepareNow(freshness);
diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
index 8806854b9ce..29791712c9d 100644
--- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
@@ -101,6 +101,7 @@ public class QueryProperties extends Properties {
map.put(CompoundName.fromComponents(Ranking.RANKING, Ranking.MATCH_PHASE, Ranking.DIVERSITY, Diversity.MINGROUPS), GetterSetter.of(query -> query.getRanking().getMatchPhase().getDiversity().getMinGroups(), (query, value) -> query.getRanking().getMatchPhase().getDiversity().setMinGroups(asLong(value, null))));
map.put(CompoundName.fromComponents(Ranking.RANKING, Ranking.MATCH_PHASE, Ranking.DIVERSITY, Diversity.CUTOFF, Diversity.FACTOR), GetterSetter.of(query -> query.getRanking().getMatchPhase().getDiversity().getCutoffFactor(), (query, value) -> query.getRanking().getMatchPhase().getDiversity().setCutoffFactor(asDouble(value, 10.0))));
map.put(CompoundName.fromComponents(Ranking.RANKING, Ranking.MATCH_PHASE, Ranking.DIVERSITY, Diversity.CUTOFF, Diversity.STRATEGY), GetterSetter.of(query -> query.getRanking().getMatchPhase().getDiversity().getCutoffStrategy(), (query, value) -> query.getRanking().getMatchPhase().getDiversity().setCutoffStrategy(asString(value, "loose"))));
+ map.put(CompoundName.fromComponents(Ranking.RANKING, Ranking.SECOND_PHASE, Ranking.RANKSCOREDROPLIMIT), GetterSetter.of(query -> query.getRanking().getSecondPhase().getRankScoreDropLimit(), (query, value) -> query.getRanking().getSecondPhase().setRankScoreDropLimit(asDouble(value, null))));
map.put(CompoundName.fromComponents(Ranking.RANKING, Ranking.GLOBAL_PHASE, Ranking.RERANKCOUNT),
GetterSetter.of(query -> query.getRanking().getGlobalPhase().getRerankCount(),
(query, value) -> query.getRanking().getGlobalPhase().setRerankCount(asInteger(value, null))));
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/SecondPhase.java b/container-search/src/main/java/com/yahoo/search/query/ranking/SecondPhase.java
new file mode 100644
index 00000000000..9ec1fb1b90e
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/SecondPhase.java
@@ -0,0 +1,73 @@
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.search.query.ranking;
+
+import com.yahoo.search.query.Ranking;
+import com.yahoo.search.query.profile.types.FieldDescription;
+import com.yahoo.search.query.profile.types.FieldType;
+import com.yahoo.search.query.profile.types.QueryProfileType;
+
+import java.util.Objects;
+
+/**
+ * The second-phase ranking settings of this query.
+ *
+ * @author toregge
+ */
+public class SecondPhase implements Cloneable {
+
+ /** The type representing the property arguments consumed by this */
+ private static final QueryProfileType argumentType;
+
+ static {
+ argumentType = new QueryProfileType(Ranking.SECOND_PHASE);
+ argumentType.setStrict(true);
+ argumentType.setBuiltin(true);
+ argumentType.addField(new FieldDescription(Ranking.RANKSCOREDROPLIMIT, FieldType.doubleType));
+ argumentType.freeze();
+ }
+ public static QueryProfileType getArgumentType() { return argumentType; }
+
+ private Double rankScoreDropLimit = null;
+
+ /** Sets the second phase rank-score-drop-limit that will be used, or null if not set */
+ public void setRankScoreDropLimit(double rankScoreDropLimit) { this.rankScoreDropLimit = rankScoreDropLimit; }
+
+ /** Returns the second phase rank-score-drop-limit that will be used, or null if not set */
+ public Double getRankScoreDropLimit() { return rankScoreDropLimit; }
+
+ /** Internal operation - DO NOT USE */
+ public void prepare(RankProperties rankProperties) {
+ if (rankScoreDropLimit == null) {
+ return;
+ }
+ rankProperties.put("vespa.hitcollector.second-phase.rankscoredroplimit", String.valueOf(rankScoreDropLimit));
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.rankScoreDropLimit);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o instanceof SecondPhase other) {
+ if ( ! Objects.equals(this.rankScoreDropLimit, other.rankScoreDropLimit)) return false;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public SecondPhase clone() {
+ try {
+ SecondPhase clone = (SecondPhase)super.clone();
+ clone.rankScoreDropLimit = this.rankScoreDropLimit;
+ return clone;
+ }
+ catch (CloneNotSupportedException e) {
+ throw new RuntimeException("Won't happen", e);
+ }
+ }
+
+}
diff --git a/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java
index 84d353ec316..62cb677dd60 100644
--- a/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/test/RankingTestCase.java
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* @author Arne Bergene Fossaa
@@ -86,4 +87,13 @@ public class RankingTestCase {
assertEquals("(0,0,10,0,10,5,20,5)", query.getRanking().getProperties().get("distanceToPath(gps_position).path").get(0));
}
+ @Test
+ void testSecondPhaseRankScoreDropLimit() {
+ var query = new Query("?query=test&ranking.secondPhase.rankScoreDropLimit=17.5");
+ var ranking = query.getRanking();
+ assertEquals(17.5, ranking.getSecondPhase().getRankScoreDropLimit());
+ ranking.prepare();
+ assertEquals("17.5", ranking.getProperties().get("vespa.hitcollector.second-phase.rankscoredroplimit").get(0));
+ }
+
}