aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/query/ranking
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/ranking')
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/Diversity.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/GlobalPhase.java68
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/MatchPhase.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java24
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/package-info.java2
8 files changed, 97 insertions, 7 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/Diversity.java b/container-search/src/main/java/com/yahoo/search/query/ranking/Diversity.java
index 15f459bc6d1..f9a3d5ab7c5 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/Diversity.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/Diversity.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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;
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/GlobalPhase.java b/container-search/src/main/java/com/yahoo/search/query/ranking/GlobalPhase.java
new file mode 100644
index 00000000000..7d28ae85ad1
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/GlobalPhase.java
@@ -0,0 +1,68 @@
+// 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 global-phase ranking settings of this query.
+ *
+ * @author arnej
+ */
+public class GlobalPhase implements Cloneable {
+
+ /** The type representing the property arguments consumed by this */
+ private static final QueryProfileType argumentType;
+
+ static {
+ argumentType = new QueryProfileType(Ranking.GLOBAL_PHASE);
+ argumentType.setStrict(true);
+ argumentType.setBuiltin(true);
+ argumentType.addField(new FieldDescription(Ranking.RERANKCOUNT, FieldType.integerType));
+ argumentType.freeze();
+ }
+ public static QueryProfileType getArgumentType() { return argumentType; }
+
+ private Integer rerankCount = null;
+
+ /**
+ * Sets the number of hits for which the global-phase function will be evaluated.
+ * When set, this overrides the setting in the rank profile.
+ */
+ public void setRerankCount(int rerankCount) { this.rerankCount = rerankCount; }
+
+ /** Returns the rerank-count that will be used, or null if not set */
+ public Integer getRerankCount() { return rerankCount; }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.rerankCount);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == this) return true;
+ if (o instanceof GlobalPhase other) {
+ if ( ! Objects.equals(this.rerankCount, other.rerankCount)) return false;
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public GlobalPhase clone() {
+ try {
+ GlobalPhase clone = (GlobalPhase)super.clone();
+ clone.rerankCount = this.rerankCount;
+ return clone;
+ }
+ catch (CloneNotSupportedException e) {
+ throw new RuntimeException("Won't happen", e);
+ }
+ }
+
+}
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/MatchPhase.java b/container-search/src/main/java/com/yahoo/search/query/ranking/MatchPhase.java
index 950e86aca77..87a3947339c 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/MatchPhase.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/MatchPhase.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.processing.IllegalInputException;
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
index 4d21f32d16d..af44f2d9de7 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.processing.IllegalInputException;
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
index 724325051f9..1c509d041fb 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.concurrent.CopyOnWriteHashMap;
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java
index f0159eae1fd..4ac5375807b 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java
@@ -1,8 +1,9 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.fs4.GetDocSumsPacket;
import com.yahoo.fs4.MapEncoder;
+import com.yahoo.tensor.Tensor;
import com.yahoo.text.JSON;
import java.nio.ByteBuffer;
@@ -11,6 +12,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
/**
* Contains the properties of a query.
@@ -61,6 +63,26 @@ public class RankProperties implements Cloneable {
return Collections.unmodifiableList(stringValues);
}
+ /**
+ * Returns a tensor (as moved from RankFeatures by prepare step) if present
+ *
+ * @throws IllegalArgumentException if the value is there but wrong type
+ */
+ public Optional<Tensor> getAsTensor(String name) {
+ List<Object> values = properties.get(name);
+ if (values == null || values.isEmpty()) return Optional.empty();
+ if (values.size() != 1) {
+ throw new IllegalArgumentException("unexpected multiple [" + values.size() + "] values for property '" + name + "'");
+ }
+ Object feature = values.get(0);
+ if (feature == null) return Optional.empty();
+ if (feature instanceof Tensor t) return Optional.of(t);
+ if (feature instanceof Double d) return Optional.of(Tensor.from(d));
+ throw new IllegalArgumentException("Expected '" + name + "' to be a tensor or double, but it is '" + feature +
+ "', this usually means that '" + name + "' is not defined in the schema. " +
+ "See https://docs.vespa.ai/en/tensor-user-guide.html#querying-with-tensors");
+ }
+
/** Removes all properties for a given name */
public void remove(String name) {
properties.remove(name);
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java
index c49b14f0978..9627c2a00d0 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// 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.processing.IllegalInputException;
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/package-info.java b/container-search/src/main/java/com/yahoo/search/query/ranking/package-info.java
index dcd9952e070..4b85d159b50 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/package-info.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/package-info.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
@ExportPackage
@PublicApi
package com.yahoo.search.query.ranking;