aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-02-08 12:24:26 +0100
committerJon Bratseth <bratseth@gmail.com>2022-02-08 12:24:26 +0100
commitba895eb72333231b976274e5f68e2ce80c7c3bbd (patch)
treea7f11f020f7acda71edd5f2dfba9ad745beef975
parentad3b8a05ccc2d0ece6f6cf93e9347fbaa84e1476 (diff)
Handle query profile values in type checking
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java24
-rw-r--r--container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java15
2 files changed, 33 insertions, 6 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
index 90d9eab687d..878a937ec67 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java
@@ -116,18 +116,30 @@ public class QueryProfileProperties extends Properties {
FieldDescription fieldDescription = type.getField(localName);
if (fieldDescription == null && type.isStrict())
throw new IllegalInputException("'" + localName + "' is not declared in " + type + ", and the type is strict");
-
// TODO: In addition to strictness, check legality along the way
if (fieldDescription != null) {
if (i == name.size() - 1) { // at the end of the path, check the assignment type
- value = fieldDescription.getType().convertFrom(value, new ConversionContext(localName,
- profile.getRegistry(),
- embedder,
- context));
- if (value == null)
+ var conversionContext = new ConversionContext(localName, profile.getRegistry(), embedder, context);
+ var convertedValue = fieldDescription.getType().convertFrom(value, conversionContext);
+ if (convertedValue == null
+ && fieldDescription.getType() instanceof QueryProfileFieldType
+ && ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType() != null) {
+ // Try the value of the query profile itself instead
+ var queryProfileValueDescription = ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType().getField("");
+ if (queryProfileValueDescription != null) {
+ convertedValue = queryProfileValueDescription.getType().convertFrom(value, conversionContext);
+ if (convertedValue == null)
+ throw new IllegalInputException("'" + value + "' is neither a " +
+ fieldDescription.getType().toInstanceDescription() + " nor a " +
+ queryProfileValueDescription.getType().toInstanceDescription());
+ }
+ }
+ else if (convertedValue == null)
throw new IllegalInputException("'" + value + "' is not a " +
fieldDescription.getType().toInstanceDescription());
+
+ value = convertedValue;
}
else if (fieldDescription.getType() instanceof QueryProfileFieldType) {
// If a type is specified, use that instead of the type implied by the name
diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
index 3b0a0ad7972..a4fd37145c8 100644
--- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
+++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java
@@ -38,6 +38,7 @@ import com.yahoo.search.query.profile.DimensionValues;
import com.yahoo.search.query.profile.QueryProfile;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry;
+import com.yahoo.search.query.profile.types.FieldDescription;
import com.yahoo.search.query.profile.types.QueryProfileType;
import com.yahoo.search.result.Hit;
import com.yahoo.search.searchchain.Execution;
@@ -1119,6 +1120,20 @@ public class QueryTestCase {
assertEquals("xml", query.getPresentation().getFormat());
assertTrue(query.getPresentation().getTensorShortForm());
}
+
+ { // Set presentation.format with a typed query profile type
+ QueryProfileRegistry registry = new QueryProfileRegistry();
+ QueryProfileType type = new QueryProfileType("mytype");
+ type.inherited().add(registry.getType("native"));
+ registry.getTypeRegistry().register(type);
+ type.addField(new FieldDescription("ranking.features.query(embedding)", "tensor(x[5])"),
+ registry.getTypeRegistry());
+ QueryProfile profile = new QueryProfile("default");
+ profile.setType(type);
+ registry.register(profile);
+ CompiledQueryProfileRegistry cRegistry = registry.compile();
+ Query query = new Query("?query=foo&presentation.format=xml", cRegistry.findQueryProfile("default"));
+ }
}
private void assertDetectionText(String expectedDetectionText, String queryString, String ... indexSpecs) {