diff options
author | Jon Bratseth <bratseth@verizonmedia.com> | 2019-01-29 09:49:27 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@verizonmedia.com> | 2019-01-29 09:49:27 +0100 |
commit | 8000ea333521c9f9e315e799d616683d3d805274 (patch) | |
tree | ef719844c4a82f79400f2a3a66f360e99033d07f /container-search | |
parent | f4303095fad0731b34638859c786320fb76251eb (diff) |
Set query properties recursively
Diffstat (limited to 'container-search')
4 files changed, 28 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..e38a461eed6 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,33 @@ 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); + System.out.println("Setting properties under " + prefix); 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; } diff --git a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java index 93299a5f589..2c094272410 100644 --- a/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java +++ b/container-search/src/test/java/com/yahoo/search/test/QueryTestCase.java @@ -305,6 +305,14 @@ public class QueryTestCase { } @Test + public void testBooleanParameter() { + QueryProfile profile = new QueryProfile("myProfile"); + Query query = new Query("/?query=something&ranking.softtimeout.enable=false", profile.compile(null)); + assertFalse(query.properties().getBoolean("ranking.softtimeout.enable")); + assertFalse(query.getRanking().getSoftTimeout().getEnable()); + } + + @Test public void testQueryProfileSubstitution2() { QueryProfile profile = new QueryProfile("myProfile"); profile.set("model.language", "en-US", null); |