diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-09-30 13:46:50 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-09-30 13:46:50 +0200 |
commit | 9fdcf8f92eaf3b47053fa2c131832dea1c792d0c (patch) | |
tree | c4d8f2a7c8297fce1b4b6f07a32ab0daeac35aaa /container-search/src/main/java/com/yahoo/search | |
parent | 1bc2cca4b527bb9a5a8c67744b0796c9fafbe024 (diff) |
Pass destination
This allows embedders to switch on it to enable bucket testing
and similar.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search')
6 files changed, 19 insertions, 19 deletions
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) { |