diff options
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile/types')
3 files changed, 16 insertions, 16 deletions
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) { |