diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-03-29 18:23:00 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-03-29 18:23:00 +0200 |
commit | f49f2b0fd89eb69437a4cda8f19a977ddb1899eb (patch) | |
tree | 051189e11565d7fbaa0989fc9ef0777f5d7ca193 /container-search | |
parent | 8767ac58447aa6189155cc1aeff5aab756a1d097 (diff) |
Undeprecate string features and be explicit
Diffstat (limited to 'container-search')
3 files changed, 21 insertions, 7 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java index 638b89f657f..a71ec5d8345 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/MapConverter.java @@ -45,8 +45,9 @@ public class MapConverter { } } - public static void convertMultiMap(Map<String, List<Object>> map, Consumer<StringProperty.Builder> stringInserter, - Consumer<TensorProperty.Builder> tensorInserter) { + public static void convertMultiMap(Map<String, List<Object>> map, + Consumer<StringProperty.Builder> stringInserter, + Consumer<TensorProperty.Builder> tensorInserter) { for (var entry : map.entrySet()) { if (entry.getValue() != null) { var key = entry.getKey(); diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java index 0e1df2b3d9a..c60cf70bd59 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/ProtobufSerialization.java @@ -185,7 +185,6 @@ public class ProtobufSerialization { } mergeRankProperties(ranking, builder::addRankProperties, builder::addTensorRankProperties); } - static byte[] serializeResult(Result searchResult) { return convertFromResult(searchResult).toByteArray(); } diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java index 7d43c09f6fb..f32b40e94d5 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankFeatures.java @@ -41,11 +41,10 @@ public class RankFeatures implements Cloneable { } /** - * Sets a rank feature to a value represented as a string. - * - * @deprecated set either a double or a tensor + * Sets a rank feature to a string. This will be available as the hash value + * of the string in ranking, so it can be used in equality comparisons + * with other string, but not for any other purpose. */ - @Deprecated // TODO: Remove on Vespa 8 public void put(String name, String value) { features.put(name, value); } @@ -93,6 +92,21 @@ public class RankFeatures implements Cloneable { } /** + * Returns a rank feature as a string, or empty if there is no value with this name. + * + * @throws IllegalArgumentException if the value is a tensor or double, not a string + */ + public Optional<String> getString(String name) { + Object feature = features.get(name); + if (feature == null) return Optional.empty(); + if (feature instanceof String) return Optional.of((String)feature); + // TODO: Use toShortString for tensors below + throw new IllegalArgumentException("Expected a string value of '" + name + "' but has " + + (feature instanceof Tensor ? ((Tensor)feature).toString() : feature)); + } + + + /** * Returns the map holding the features of this. * This map may be modified to change the rank features of the query. */ |