diff options
author | Jon Bratseth <bratseth@oath.com> | 2018-04-26 14:37:10 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2018-04-26 14:37:10 +0200 |
commit | d11721c9bb7b532a2c3471232e68a95ce442d895 (patch) | |
tree | 0e3ca22eb591a819ed1c83c1766632ac27ecc21f /container-search/src/main/java/com/yahoo/search/query/profile | |
parent | fa3121763f67a3f4989ef9e4db88c27a802e3783 (diff) |
Include Query model in listProperties
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/query/profile')
5 files changed, 34 insertions, 32 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/DumpTool.java b/container-search/src/main/java/com/yahoo/search/query/profile/DumpTool.java index bfdf49bf50a..572a78addd2 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/DumpTool.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/DumpTool.java @@ -17,8 +17,8 @@ public class DumpTool { /** Creates and returns a dump from some parameters */ public String resolveAndDump(String... args) { - if (args.length==0 || args[0].startsWith("-")) { - StringBuilder result=new StringBuilder(); + if (args.length == 0 || args[0].startsWith("-")) { + StringBuilder result = new StringBuilder(); result.append("Dumps all resolved query profile properties for a set of dimension values\n"); result.append("USAGE: dump [query-profile] [dir]? [parameters]?\n"); result.append(" and [query-profile] is the name of the query profile to dump the values of\n"); @@ -37,37 +37,37 @@ public class DumpTool { } // Find what the arguments means - if (args.length>=3) { - return dump(args[0],args[1],args[2]); + if (args.length >= 3) { + return dump(args[0], args[1], args[2]); } - else if (args.length==2) { - if (args[1].indexOf("=")>=0) - return dump(args[0],"",args[1]); + else if (args.length == 2) { + if (args[1].contains("=")) + return dump(args[0], "", args[1]); else - return dump(args[0],args[1],""); + return dump(args[0], args[1],""); } else { // args.length=1 - return dump(args[0],"",""); + return dump(args[0], "", ""); } } private String dump(String profileName,String dir,String parameters) { // Import profiles if (dir.isEmpty()) - dir="."; - File dirInAppPackage=new File(dir,"search/query-profiles"); + dir = "."; + File dirInAppPackage = new File(dir, "search/query-profiles"); if (dirInAppPackage.exists()) - dir=dirInAppPackage.getPath(); + dir = dirInAppPackage.getPath(); QueryProfileXMLReader reader = new QueryProfileXMLReader(); QueryProfileRegistry registry = reader.read(dir); registry.freeze(); // Dump (through query to get wiring & parameter parsing done easily) Query query = new Query("?" + parameters, registry.compile().findQueryProfile(profileName)); - Map<String,Object> properties=query.properties().listProperties(); + Map<String,Object> properties = query.properties().listProperties(); // Create result - StringBuilder b=new StringBuilder(); + StringBuilder b = new StringBuilder(); for (Map.Entry<String,Object> property : properties.entrySet()) { b.append(property.getKey()); b.append("="); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java index a347fbfb3ab..0e6af6113b5 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java @@ -234,17 +234,18 @@ public class QueryProfile extends FreezableSimpleComponent implements Cloneable * will return {"d" => "a.d-value","e" => "a.e-value"} */ public Map<String, Object> listValues(CompoundName prefix, Map<String, String> context, Properties substitution) { - DimensionBinding dimensionBinding=DimensionBinding.createFrom(getDimensions(),context); + DimensionBinding dimensionBinding = DimensionBinding.createFrom(getDimensions(),context); - AllValuesQueryProfileVisitor visitor=new AllValuesQueryProfileVisitor(prefix); + AllValuesQueryProfileVisitor visitor = new AllValuesQueryProfileVisitor(prefix); accept(visitor,dimensionBinding, null); - Map<String,Object> values=visitor.getResult(); + Map<String,Object> values = visitor.getResult(); - if (substitution==null) return values; + if (substitution == null) return values; for (Map.Entry<String, Object> entry : values.entrySet()) { if (entry.getValue().getClass() == String.class) continue; // Shortcut - if (entry.getValue() instanceof SubstituteString) - entry.setValue(((SubstituteString)entry.getValue()).substitute(context,substitution)); + if (entry.getValue() instanceof SubstituteString) { + entry.setValue(((SubstituteString) entry.getValue()).substitute(context, substitution)); + } } return values; } diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java index 324c1bf796e..3e1f664cf87 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java @@ -100,7 +100,8 @@ public class QueryProfileProperties extends Properties { if (i == name.size()-1 && fieldDescription != null) { // at the end of the path, check the assignment type value = fieldDescription.getType().convertFrom(value, profile.getRegistry()); if (value == null) - throw new IllegalArgumentException("'" + value + "' is not a " + fieldDescription.getType().toInstanceDescription()); + throw new IllegalArgumentException("'" + value + "' is not a " + + fieldDescription.getType().toInstanceDescription()); } } } @@ -138,7 +139,6 @@ public class QueryProfileProperties extends Properties { if (context == null) context = Collections.emptyMap(); Map<String, Object> properties = profile.listValues(path, context, substitution); - properties.putAll(super.listProperties(path, context, substitution)); if (references != null) { diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java b/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java index ca492de101f..36b38ad8d03 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java @@ -56,8 +56,8 @@ public class SubstituteString { * Perform the substitution in this, by looking up in the given query profile, * and returns the resulting string */ - public String substitute(Map<String,String> context,Properties substitution) { - StringBuilder b=new StringBuilder(); + public String substitute(Map<String, String> context, Properties substitution) { + StringBuilder b = new StringBuilder(); for (Component component : components) b.append(component.getValue(context,substitution)); return b.toString(); diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java index fca1124665b..7ac73947905 100644 --- a/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java +++ b/container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java @@ -12,6 +12,7 @@ import com.yahoo.search.query.profile.types.QueryProfileType; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -109,7 +110,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable * For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") * will return {"d" => "a.d-value","e" => "a.e-value"} */ - public final Map<String, Object> listValues(final String prefix,Map<String,String> context) { + public final Map<String, Object> listValues(final String prefix,Map<String, String> context) { return listValues(new CompoundName(prefix), context); } /** @@ -118,7 +119,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable * For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") * will return {"d" => "a.d-value","e" => "a.e-value"} */ - public final Map<String, Object> listValues(final CompoundName prefix,Map<String,String> context) { + public final Map<String, Object> listValues(final CompoundName prefix,Map<String, String> context) { return listValues(prefix, context, null); } /** @@ -127,7 +128,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable * For example, if {a.d => "a.d-value" ,a.e => "a.e-value", b.d => "b.d-value", then calling listValues("a") * will return {"d" => "a.d-value","e" => "a.e-value"} */ - public Map<String, Object> listValues(CompoundName prefix, Map<String,String> context, Properties substitution) { + public Map<String, Object> listValues(CompoundName prefix, Map<String, String> context, Properties substitution) { Map<String, Object> values = new HashMap<>(); for (Map.Entry<CompoundName, DimensionalValue<Object>> entry : entries.entrySet()) { if ( entry.getKey().size() <= prefix.size()) continue; @@ -144,19 +145,19 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable } public final Object get(String name) { - return get(name, Collections.<String,String>emptyMap()); + return get(name, Collections.emptyMap()); } - public final Object get(String name, Map<String,String> context) { + public final Object get(String name, Map<String, String> context) { return get(name, context, new QueryProfileProperties(this)); } - public final Object get(String name, Map<String,String> context, Properties substitution) { + public final Object get(String name, Map<String, String> context, Properties substitution) { return get(new CompoundName(name), context, substitution); } public final Object get(CompoundName name, Map<String, String> context, Properties substitution) { return substitute(entries.get(name, context), context, substitution); } - private Object substitute(Object value, Map<String,String> context, Properties substitution) { + private Object substitute(Object value, Map<String, String> context, Properties substitution) { if (value == null) return value; if (substitution == null) return value; if (value.getClass() != SubstituteString.class) return value; @@ -165,7 +166,7 @@ public class CompiledQueryProfile extends AbstractComponent implements Cloneable /** Throws IllegalArgumentException if the given string is not a valid query profile name */ private static void validateName(String name) { - Matcher nameMatcher=namePattern.matcher(name); + Matcher nameMatcher = namePattern.matcher(name); if ( ! nameMatcher.matches()) throw new IllegalArgumentException("Illegal name '" + name + "'"); } |