diff options
author | Jon Bratseth <bratseth@oath.com> | 2019-01-29 10:00:36 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-29 10:00:36 +0100 |
commit | 90c844e2b4441653f7caf8eb1f26b703a3fb5526 (patch) | |
tree | 348732d36f4b3d4db32834a228d45434111819c4 /container-search/src/main/java/com/yahoo/search | |
parent | 75ee7deb2a3e0cf8f33126b1337257a42035c844 (diff) | |
parent | 1414ca797b266a0dbf5760bd931852c09a8b3879 (diff) |
Merge pull request #8276 from vespa-engine/bratseth/set-query-properties-recursively
Bratseth/set query properties recursively
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search')
3 files changed, 19 insertions, 16 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/Query.java b/container-search/src/main/java/com/yahoo/search/Query.java index 73335037b94..e599d06f6c7 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -386,32 +386,32 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { * one of its dependent objects. This will ensure the appropriate setters are called on this and all * dependent objects for the appropriate subset of the given property values */ - private void setFieldsFrom(Properties properties, Map<String,String> context) { - setFrom(properties,Query.getArgumentType(), context); - setFrom(properties,Model.getArgumentType(), context); - setFrom(properties,Presentation.getArgumentType(), context); - setFrom(properties,Ranking.getArgumentType(), context); - setFrom(properties, Select.getArgumentType(), context); + private void setFieldsFrom(Properties properties, Map<String, String> context) { + setFrom("", properties, Query.getArgumentType(), context); } /** * For each field in the given query profile type, take the corresponding value from originalProperties - * (if any) set it to properties(). + * (if any) set it to properties(), recursively. */ - private void setFrom(Properties originalProperties,QueryProfileType arguments,Map<String,String> context) { - String prefix = getPrefix(arguments); + private void setFrom(String prefix, Properties originalProperties, QueryProfileType arguments, Map<String, String> context) { + prefix = prefix + getPrefix(arguments); for (FieldDescription field : arguments.fields().values()) { String fullName = prefix + field.getName(); - if (field.getType() == FieldType.genericQueryProfileType) { - for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName,context).entrySet()) { + if (field.getType() == FieldType.genericQueryProfileType) { // Generic map + for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName, context).entrySet()) { try { properties().set(fullName + "." + entry.getKey(), entry.getValue(), context); } catch (IllegalArgumentException e) { throw new QueryException("Invalid request parameter", e); } } - } else { - Object value = originalProperties.get(fullName,context); + } + else if (field.getType() instanceof QueryProfileFieldType) { // Nested arguments + setFrom(prefix, originalProperties, ((QueryProfileFieldType)field.getType()).getQueryProfileType(), context); + } + else { + Object value = originalProperties.get(fullName, context); if (value != null) { try { properties().set(fullName, value, context); diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java b/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java index c8033955a26..4158b0e7476 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/RankProperties.java @@ -20,7 +20,7 @@ import java.util.Map; */ public class RankProperties implements Cloneable { - private Map<String, List<Object>> properties = new LinkedHashMap<>(); + private Map<String, List<Object>> properties; public RankProperties() { this(new LinkedHashMap<>()); diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java index a05ecee8a1e..5132d954687 100644 --- a/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java +++ b/container-search/src/main/java/com/yahoo/search/query/ranking/SoftTimeout.java @@ -30,8 +30,9 @@ public class SoftTimeout implements Cloneable { argumentType = new QueryProfileType(Ranking.SOFTTIMEOUT); argumentType.setStrict(true); argumentType.setBuiltin(true); - argumentType.addField(new FieldDescription(TAILCOST, "double")); argumentType.addField(new FieldDescription(ENABLE, "boolean")); + argumentType.addField(new FieldDescription(FACTOR, "double")); + argumentType.addField(new FieldDescription(TAILCOST, "double")); argumentType.freeze(); } public static QueryProfileType getArgumentType() { return argumentType; } @@ -40,7 +41,9 @@ public class SoftTimeout implements Cloneable { private Double factor = null; private Double tailcost = null; - public void setEnable(boolean enable) { this.enabled = enable; } + public void setEnable(boolean enable) { + this.enabled = enable; + } public Boolean getEnable() { return enabled; } |