diff options
author | Jon Bratseth <bratseth@oath.com> | 2019-01-08 10:26:06 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@oath.com> | 2019-01-08 10:26:06 +0100 |
commit | 89a35afd50c74a738ed160eae03d8f6384af6834 (patch) | |
tree | cbd983878eac733fbfa623f17c5dc7076b1c4269 /container-search/src/main | |
parent | 8191ade44977f2874d60fc6811bbb9427a60510d (diff) |
Include queryProfile as a regular parameter
Diffstat (limited to 'container-search/src/main')
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/Query.java | 28 | ||||
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java | 40 |
2 files changed, 35 insertions, 33 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 8e5e14a3aac..3159bfc4658 100644 --- a/container-search/src/main/java/com/yahoo/search/Query.java +++ b/container-search/src/main/java/com/yahoo/search/Query.java @@ -187,6 +187,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { public static final CompoundName OFFSET = new CompoundName("offset"); public static final CompoundName HITS = new CompoundName("hits"); + public static final CompoundName QUERY_PROFILE = new CompoundName("queryProfile"); public static final CompoundName SEARCH_CHAIN = new CompoundName("searchChain"); public static final CompoundName TRACE_LEVEL = new CompoundName("traceLevel"); public static final CompoundName NO_CACHE = new CompoundName("noCache"); @@ -202,6 +203,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { argumentType.addField(new FieldDescription(OFFSET.toString(), "integer", "offset start")); argumentType.addField(new FieldDescription(HITS.toString(), "integer", "hits count")); // TODO: Should this be added to com.yahoo.search.query.properties.QueryProperties? If not, why not? + argumentType.addField(new FieldDescription(QUERY_PROFILE.toString(), "string")); argumentType.addField(new FieldDescription(SEARCH_CHAIN.toString(), "string")); argumentType.addField(new FieldDescription(TRACE_LEVEL.toString(), "integer", "tracelevel")); argumentType.addField(new FieldDescription(NO_CACHE.toString(), "boolean", "nocache")); @@ -411,10 +413,10 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { } } } else { - Object value=originalProperties.get(fullName,context); - if (value!=null) { + Object value = originalProperties.get(fullName,context); + if (value != null) { try { - properties().set(fullName,value,context); + properties().set(fullName, value, context); } catch (IllegalArgumentException e) { throw new QueryException("Invalid request parameter", e); } @@ -427,7 +429,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { private void setPropertiesFromRequestMap(Map<String, String> requestMap, Properties properties) { for (Map.Entry<String, String> entry : requestMap.entrySet()) { try { - if (entry.getKey().equals("queryProfile")) continue; + //if (entry.getKey().equals("queryProfile")) continue; properties.set(entry.getKey(), entry.getValue(), requestMap); } catch (IllegalArgumentException e) { @@ -446,12 +448,12 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { */ private void traceProperties() { if (traceLevel == 0) return; - CompiledQueryProfile profile=null; - QueryProfileProperties profileProperties=properties().getInstance(QueryProfileProperties.class); - if (profileProperties!=null) - profile=profileProperties.getQueryProfile(); + CompiledQueryProfile profile = null; + QueryProfileProperties profileProperties = properties().getInstance(QueryProfileProperties.class); + if (profileProperties != null) + profile = profileProperties.getQueryProfile(); - if (profile==null) + if (profile == null) trace("No query profile is used", false, 1); else trace("Using " + profile.toString(), false, 1); @@ -466,7 +468,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { b.append(requestProperty.getKey()); b.append("="); - b.append(String.valueOf(resolvedValue)); // (may be null) + b.append(resolvedValue); // (may be null) b.append(" ("); if (profile != null && ! profile.isOverridable(new CompoundName(requestProperty.getKey()), requestProperties())) @@ -476,8 +478,8 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { b.append(")\n"); mentioned.add(requestProperty.getKey()); } - if (profile!=null) { - appendQueryProfileProperties(profile,mentioned,b); + if (profile != null) { + appendQueryProfileProperties(profile, mentioned, b); } trace(b.toString(),false,4); } @@ -487,7 +489,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable { } private void appendQueryProfileProperties(CompiledQueryProfile profile,Set<String> mentioned,StringBuilder b) { - for (Map.Entry<String,Object> property : profile.listValues("",requestProperties()).entrySet()) { + for (Map.Entry<String,Object> property : profile.listValues("", requestProperties()).entrySet()) { if ( ! mentioned.contains(property.getKey())) b.append(property.getKey() + "=" + property.getValue() + " (value from query profile)<br/>\n"); } 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 36b38ad8d03..3252f0f4662 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 @@ -27,23 +27,23 @@ public class SubstituteString { * Returns a new SubstituteString if the given string contains substitutions, null otherwise. */ public static SubstituteString create(String value) { - int lastEnd=0; - int start=value.indexOf("%{"); - if (start<0) return null; // Shortcut - List<Component> components=new ArrayList<>(); - while (start>=0) { - int end=value.indexOf("}",start+2); - if (end<0) + int lastEnd = 0; + int start = value.indexOf("%{"); + if (start < 0) return null; // Shortcut + List<Component> components = new ArrayList<>(); + while (start >= 0) { + int end = value.indexOf("}", start + 2); + if (end < 0) throw new IllegalArgumentException("Unterminated value substitution '" + value.substring(start) + "'"); - String propertyName=value.substring(start+2,end); - if (propertyName.indexOf("%{")>=0) + String propertyName = value.substring(start+2,end); + if (propertyName.indexOf("%{") >= 0) throw new IllegalArgumentException("Unterminated value substitution '" + value.substring(start) + "'"); - components.add(new StringComponent(value.substring(lastEnd,start))); + components.add(new StringComponent(value.substring(lastEnd, start))); components.add(new PropertyComponent(propertyName)); - lastEnd=end+1; - start=value.indexOf("%{",lastEnd); + lastEnd = end+1; + start = value.indexOf("%{", lastEnd); } - components.add(new StringComponent(value.substring(lastEnd,value.length()))); + components.add(new StringComponent(value.substring(lastEnd))); return new SubstituteString(components, value); } @@ -83,7 +83,7 @@ public class SubstituteString { private abstract static class Component { - protected abstract String getValue(Map<String,String> context,Properties substitution); + protected abstract String getValue(Map<String, String> context, Properties substitution); } @@ -92,11 +92,11 @@ public class SubstituteString { private final String value; public StringComponent(String value) { - this.value=value; + this.value = value; } @Override - public String getValue(Map<String,String> context,Properties substitution) { + public String getValue(Map<String, String> context, Properties substitution) { return value; } @@ -112,13 +112,13 @@ public class SubstituteString { private final String propertyName; public PropertyComponent(String propertyName) { - this.propertyName=propertyName; + this.propertyName = propertyName; } @Override - public String getValue(Map<String,String> context,Properties substitution) { - Object value=substitution.get(propertyName,context,substitution); - if (value==null) return ""; + public String getValue(Map<String,String> context, Properties substitution) { + Object value = substitution.get(propertyName, context, substitution); + if (value == null) return ""; return String.valueOf(value); } |