diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-10-01 11:09:08 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-10-01 11:09:08 +0200 |
commit | ac2519a8842a6397e4abd434439e9dddd2924394 (patch) | |
tree | 792275efbb88966a27a7ce54cc31465b563d7ad0 /container-search | |
parent | 380b9fa780ead9bcce0e824f7b6ee305e37dec43 (diff) |
Encapsulate in a context
Diffstat (limited to 'container-search')
2 files changed, 10 insertions, 5 deletions
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 05befb24da0..76fb28ebb34 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,6 +1,7 @@ // 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.process.Embedder; import com.yahoo.search.query.profile.QueryProfileRegistry; import com.yahoo.tensor.Tensor; import com.yahoo.tensor.TensorType; @@ -52,7 +53,11 @@ public class TensorFieldType extends FieldType { 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 context.embedder().embed(text, context.language(), context.destination(), type); + return context.embedder().embed(text, toEmbedderContext(context), type); + } + + private Embedder.Context toEmbedderContext(ConversionContext context) { + return new Embedder.Context(context.destination()).setLanguage(context.language()); } public static TensorFieldType fromTypeString(String s) { 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 e63c7711ff2..f11e5614635 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 @@ -747,16 +747,16 @@ public class QueryProfileTypeTestCase { } @Override - public List<Integer> embed(String text, Language language, String destination) { + public List<Integer> embed(String text, Embedder.Context context) { fail("Unexpected call"); return null; } @Override - public Tensor embed(String text, Language language, String destination, TensorType tensorType) { + public Tensor embed(String text, Embedder.Context context, TensorType tensorType) { assertEquals(expectedText, text); - assertEquals(expectedLanguage, language); - assertEquals(expectedDestination, destination); + assertEquals(expectedLanguage, context.getLanguage()); + assertEquals(expectedDestination, context.getDestination()); assertEquals(tensorToReturn.type(), tensorType); return tensorToReturn; } |