aboutsummaryrefslogtreecommitdiffstats
path: root/container-search
diff options
context:
space:
mode:
Diffstat (limited to 'container-search')
-rw-r--r--container-search/abi-spec.json3
-rw-r--r--container-search/src/main/java/com/yahoo/search/federation/ForwardingSearcher.java1
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java3
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java18
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileFieldType.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java12
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java2
-rw-r--r--container-search/src/test/java/com/yahoo/search/query/profile/types/test/QueryProfileTypeTestCase.java23
8 files changed, 38 insertions, 26 deletions
diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json
index b7ce40f19a2..e4c1a561dee 100644
--- a/container-search/abi-spec.json
+++ b/container-search/abi-spec.json
@@ -6259,7 +6259,8 @@
"public"
],
"methods": [
- "public void <init>(com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry, com.yahoo.language.process.Embedder, java.util.Map)",
+ "public void <init>(java.lang.String, com.yahoo.search.query.profile.compiled.CompiledQueryProfileRegistry, com.yahoo.language.process.Embedder, java.util.Map)",
+ "public java.lang.String destination()",
"public static com.yahoo.search.query.profile.types.ConversionContext empty()"
],
"fields": []
diff --git a/container-search/src/main/java/com/yahoo/search/federation/ForwardingSearcher.java b/container-search/src/main/java/com/yahoo/search/federation/ForwardingSearcher.java
index d6bfd6dcd82..e8a2875b9b9 100644
--- a/container-search/src/main/java/com/yahoo/search/federation/ForwardingSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/federation/ForwardingSearcher.java
@@ -20,7 +20,6 @@ import com.yahoo.search.searchchain.Execution;
* semantics are not necessary for the application.
*
* @see FederationSearcher
- * @since 5.0.13
* @author Steinar Knutsen
*/
@After("*")
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 53be827073c..bcf4f568998 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
@@ -121,7 +121,8 @@ public class QueryProfileProperties extends Properties {
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(profile.getRegistry(),
+ value = fieldDescription.getType().convertFrom(value, new ConversionContext(localName,
+ profile.getRegistry(),
embedder,
context));
if (value == null)
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java
index e5b9eb1c1cd..8dfb67a9d5f 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/ConversionContext.java
@@ -12,29 +12,35 @@ import java.util.Map;
*/
public class ConversionContext {
+ private final String destination;
private final CompiledQueryProfileRegistry registry;
private final Embedder embedder;
private final Language language;
- public ConversionContext(CompiledQueryProfileRegistry registry, Embedder embedder, Map<String, String> context) {
+ public ConversionContext(String destination, CompiledQueryProfileRegistry registry, Embedder embedder,
+ Map<String, String> context) {
+ this.destination = destination;
this.registry = registry;
this.embedder = embedder;
this.language = context.containsKey("language") ? Language.fromLanguageTag(context.get("language"))
: Language.UNKNOWN;
}
+ /** Returns the local name of the field which will receive the converted value (or null when this is empty) */
+ public String destination() { return destination; }
+
/** Returns the profile registry, or null if none */
- CompiledQueryProfileRegistry getRegistry() {return registry;}
+ CompiledQueryProfileRegistry registry() {return registry;}
- /** Returns the configured encoder, never null */
- Embedder getEncoder() { return embedder; }
+ /** Returns the configured embedder, never null */
+ Embedder embedder() { return embedder; }
/** Returns the language, which is never null but may be UNKNOWN */
- Language getLanguage() { return language; }
+ Language language() { return language; }
/** Returns an empty context */
public static ConversionContext empty() {
- return new ConversionContext(null, Embedder.throwsOnUse, Map.of());
+ return new ConversionContext(null, null, Embedder.throwsOnUse, Map.of());
}
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileFieldType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileFieldType.java
index ff12224823f..2b649d81ec8 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileFieldType.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileFieldType.java
@@ -60,7 +60,7 @@ public class QueryProfileFieldType extends FieldType {
String profileId = object.toString();
if (profileId.startsWith("ref:"))
profileId = profileId.substring("ref:".length());
- CompiledQueryProfile profile = context.getRegistry().getComponent(profileId);
+ CompiledQueryProfile profile = context.registry().getComponent(profileId);
if (profile == null) return null;
if (type != null && ! type.equals(profile.getType())) return null;
return profile;
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
index cd21f0b3a61..05befb24da0 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/TensorFieldType.java
@@ -1,8 +1,6 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query.profile.types;
-import com.yahoo.language.Language;
-import com.yahoo.language.process.Embedder;
import com.yahoo.search.query.profile.QueryProfileRegistry;
import com.yahoo.tensor.Tensor;
import com.yahoo.tensor.TensorType;
@@ -44,21 +42,17 @@ public class TensorFieldType extends FieldType {
@Override
public Object convertFrom(Object o, ConversionContext context) {
- return convertFrom(o, context.getEncoder(), context.getLanguage());
- }
-
- private Object convertFrom(Object o, Embedder embedder, Language language) {
if (o instanceof Tensor) return o;
- if (o instanceof String && ((String)o).startsWith("embed(")) return encode((String)o, embedder, language);
+ if (o instanceof String && ((String)o).startsWith("embed(")) return encode((String)o, context);
if (o instanceof String) return Tensor.from(type, (String)o);
return null;
}
- private Tensor encode(String s, Embedder embedder, Language language) {
+ private Tensor encode(String s, ConversionContext context) {
if ( ! s.endsWith(")"))
throw new IllegalArgumentException("Expected any string enclosed in embed(), but the argument does not end by ')'");
String text = s.substring("embed(".length(), s.length() - 1);
- return embedder.embed(text, language, type);
+ return context.embedder().embed(text, context.language(), context.destination(), type);
}
public static TensorFieldType fromTypeString(String s) {
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 3a426656185..1fa91c73fb0 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
@@ -380,7 +380,7 @@ public class QueryProperties extends Properties {
if (type == null) return value; // no type info -> keep as string
FieldDescription field = type.getField(key);
if (field == null) return value; // ditto
- return field.getType().convertFrom(value, new ConversionContext(profileRegistry, embedder, context));
+ return field.getType().convertFrom(value, new ConversionContext(key, profileRegistry, embedder, context));
}
private void throwIllegalParameter(String key,String namespace) {
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 e22263070e0..e63c7711ff2 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
@@ -447,24 +447,31 @@ public class QueryProfileTypeTestCase {
CompiledQueryProfileRegistry cRegistry = registry.compile();
String textToEmbed = "text to embed into a tensor";
+ String destinationFeature = "query(myTensor4)";
Tensor expectedTensor = Tensor.from("tensor<float>(x[5]):[3,7,4,0,0]]");
- Query query1 = new Query.Builder().setRequest(HttpRequest.createTestRequest("?" + urlEncode("ranking.features.query(myTensor4)") +
+ Query query1 = new Query.Builder().setRequest(HttpRequest.createTestRequest("?" + urlEncode("ranking.features." + destinationFeature) +
"=" + urlEncode("embed(" + textToEmbed + ")"),
com.yahoo.jdisc.http.HttpRequest.Method.GET))
.setQueryProfile(cRegistry.getComponent("test"))
- .setEmbedder(new MockEmbedder(textToEmbed, Language.UNKNOWN, expectedTensor))
+ .setEmbedder(new MockEmbedder(textToEmbed,
+ Language.UNKNOWN,
+ destinationFeature,
+ expectedTensor))
.build();
assertEquals(0, query1.errors().size());
assertEquals(expectedTensor, query1.properties().get("ranking.features.query(myTensor4)"));
assertEquals(expectedTensor, query1.getRanking().getFeatures().getTensor("query(myTensor4)").get());
// Explicit language
- Query query2 = new Query.Builder().setRequest(HttpRequest.createTestRequest("?" + urlEncode("ranking.features.query(myTensor4)") +
+ Query query2 = new Query.Builder().setRequest(HttpRequest.createTestRequest("?" + urlEncode("ranking.features." + destinationFeature) +
"=" + urlEncode("embed(" + textToEmbed + ")") +
"&language=en",
com.yahoo.jdisc.http.HttpRequest.Method.GET))
.setQueryProfile(cRegistry.getComponent("test"))
- .setEmbedder(new MockEmbedder(textToEmbed, Language.ENGLISH, expectedTensor))
+ .setEmbedder(new MockEmbedder(textToEmbed,
+ Language.ENGLISH,
+ destinationFeature,
+ expectedTensor))
.build();
assertEquals(0, query2.errors().size());
assertEquals(expectedTensor, query2.properties().get("ranking.features.query(myTensor4)"));
@@ -726,26 +733,30 @@ public class QueryProfileTypeTestCase {
private final String expectedText;
private final Language expectedLanguage;
+ private final String expectedDestination;
private final Tensor tensorToReturn;
public MockEmbedder(String expectedText,
Language expectedLanguage,
+ String expectedDestination,
Tensor tensorToReturn) {
this.expectedText = expectedText;
this.expectedLanguage = expectedLanguage;
+ this.expectedDestination = expectedDestination;
this.tensorToReturn = tensorToReturn;
}
@Override
- public List<Integer> embed(String text, Language language) {
+ public List<Integer> embed(String text, Language language, String destination) {
fail("Unexpected call");
return null;
}
@Override
- public Tensor embed(String text, Language language, TensorType tensorType) {
+ public Tensor embed(String text, Language language, String destination, TensorType tensorType) {
assertEquals(expectedText, text);
assertEquals(expectedLanguage, language);
+ assertEquals(expectedDestination, destination);
assertEquals(tensorToReturn.type(), tensorType);
return tensorToReturn;
}