aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/test/java/com/yahoo/search/query
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-03-28 11:49:56 +0200
committerJon Bratseth <bratseth@gmail.com>2022-03-28 11:49:56 +0200
commit13100e8dcc72b7c879727e5d96e1fdfceb2d3bcc (patch)
tree59e485fc832caf10b99c41f526fb4ea7e5cdeb76 /container-search/src/test/java/com/yahoo/search/query
parentbf003f9653c0ff3d139f4cbda93b0fbc7c62cfcc (diff)
Add parent referenced to Ranking and RankFeatures
Diffstat (limited to 'container-search/src/test/java/com/yahoo/search/query')
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java44
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/test/RankFeaturesTestCase.java8
2 files changed, 49 insertions, 3 deletions
diff --git a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
index a1556aac189..20678f3b7bb 100644
--- a/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java
@@ -20,6 +20,7 @@ import com.yahoo.search.query.profile.types.FieldType;
import com.yahoo.search.query.profile.types.QueryProfileType;
import com.yahoo.search.query.profile.types.QueryProfileTypeRegistry;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import java.net.URLEncoder;
@@ -423,6 +424,49 @@ public class QueryProfileTypeTestCase {
assertEquals(Tensor.from(tensorString), query.getRanking().getFeatures().getTensor("query(myTensor1)").get());
}
+ @Test
+ public void testTensorRankFeatureSetProgrammatically() {
+ QueryProfile profile = new QueryProfile("test");
+ profile.setType(testtype);
+ registry.register(profile);
+
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ String tensorString = "{{a:a1, b:b1}:1.0, {a:a2, b:b1}:2.0}}";
+ Query query = new Query(HttpRequest.createTestRequest("?", com.yahoo.jdisc.http.HttpRequest.Method.GET),
+ cRegistry.getComponent("test"));
+ query.properties().set("ranking.features.query(myTensor1)", Tensor.from(tensorString));
+ assertEquals(Tensor.from(tensorString), query.getRanking().getFeatures().getTensor("query(myTensor1)").get());
+ }
+
+ @Test
+ @Ignore
+ public void testTensorRankFeatureSetProgrammaticallyWithWrongType() {
+ QueryProfile profile = new QueryProfile("test");
+ profile.setType(testtype);
+ registry.register(profile);
+
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ String tensorString = "tensor(x[3]):[0.1, 0.2, 0.3]";
+ Query query = new Query(HttpRequest.createTestRequest("?", com.yahoo.jdisc.http.HttpRequest.Method.GET),
+ cRegistry.getComponent("test"));
+ try {
+ query.getRanking().getFeatures().put("query(myTensor1)",Tensor.from(tensorString));
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("'query(myTensor1)' must be of type tensor(a{},b{}) but was of type tensor(x[3])",
+ e.getMessage());
+ }
+ try {
+ query.properties().set("ranking.features.query(myTensor1)", Tensor.from(tensorString));
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("'query(myTensor1)' must be of type tensor(a{},b{}) but was of type tensor(x[3])",
+ e.getMessage());
+ }
+ }
+
// Expected to work exactly as testTensorRankFeatureInRequest
@Test
public void testTensorRankFeatureInRequestWithInheritedQueryProfileType() {
diff --git a/container-search/src/test/java/com/yahoo/search/query/test/RankFeaturesTestCase.java b/container-search/src/test/java/com/yahoo/search/query/test/RankFeaturesTestCase.java
index 8848e33c365..0644a2b02e8 100644
--- a/container-search/src/test/java/com/yahoo/search/query/test/RankFeaturesTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/query/test/RankFeaturesTestCase.java
@@ -2,6 +2,8 @@
package com.yahoo.search.query.test;
import com.yahoo.io.GrowableByteBuffer;
+import com.yahoo.search.Query;
+import com.yahoo.search.query.Ranking;
import com.yahoo.search.query.ranking.RankFeatures;
import com.yahoo.search.query.ranking.RankProperties;
import com.yahoo.tensor.Tensor;
@@ -36,11 +38,11 @@ public class RankFeaturesTestCase {
@Test
@SuppressWarnings("deprecation")
public void requireThatRankFeaturesUsingDoubleAndDoubleToStringEncodeTheSameWay() {
- RankFeatures withDouble = new RankFeatures();
+ RankFeatures withDouble = new RankFeatures(new Ranking(new Query()));
withDouble.put("query(myDouble)", 3.8);
assertEquals(3.8, withDouble.getDouble("query(myDouble)").getAsDouble(), 0.000001);
- RankFeatures withString = new RankFeatures();
+ RankFeatures withString = new RankFeatures(new Ranking(new Query()));
withString.put("query(myDouble)", String.valueOf(3.8));
RankProperties withDoubleP = new RankProperties();
@@ -99,7 +101,7 @@ public class RankFeaturesTestCase {
}
private static RankProperties createRankPropertiesWithTensors(List<Entry> entries) {
- RankFeatures features = new RankFeatures();
+ RankFeatures features = new RankFeatures(new Ranking(new Query()));
for (Entry entry : entries) {
features.put(entry.key, entry.tensor);
}