aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2018-04-26 14:37:10 +0200
committerJon Bratseth <bratseth@oath.com>2018-04-26 14:37:10 +0200
commitd11721c9bb7b532a2c3471232e68a95ce442d895 (patch)
tree0e3ca22eb591a819ed1c83c1766632ac27ecc21f /container-search/src/main
parentfa3121763f67a3f4989ef9e4db88c27a802e3783 (diff)
Include Query model in listProperties
Diffstat (limited to 'container-search/src/main')
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java21
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/DumpTool.java28
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfile.java13
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/QueryProfileProperties.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/SubstituteString.java4
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/compiled/CompiledQueryProfile.java17
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java67
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/properties/RequestContextProperties.java10
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java2
9 files changed, 90 insertions, 76 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 20f87afacc1..c6ce9dc404a 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -111,7 +111,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** Converts a type argument value into a query type */
public static Type getType(String typeString) {
for (Type type:Type.values())
- if(type.stringValue.equals(typeString))
+ if (type.stringValue.equals(typeString))
return type;
return ALL;
}
@@ -141,10 +141,10 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** Whether this query is forbidden to access cached information */
- private boolean noCache=false;
+ private boolean noCache = false;
/** Whether or not grouping should use a session cache */
- private boolean groupingSessionCache=false;
+ private boolean groupingSessionCache = false;
//-------------- Generic property containers --------------------------------
@@ -212,8 +212,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
public static QueryProfileType getArgumentType() { return argumentType; }
- /** The aliases of query properties, these are always the same */
- // Note: Don't make static for now as GSM calls this through reflection
+ /** The aliases of query properties */
private static Map<String,CompoundName> propertyAliases;
static {
Map<String,CompoundName> propertyAliasesBuilder = new HashMap<>();
@@ -223,11 +222,11 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
addAliases(Presentation.getArgumentType(), propertyAliasesBuilder);
propertyAliases = ImmutableMap.copyOf(propertyAliasesBuilder);
}
- private static void addAliases(QueryProfileType arguments,Map<String,CompoundName> aliases) {
- String prefix=getPrefix(arguments);
+ private static void addAliases(QueryProfileType arguments, Map<String, CompoundName> aliases) {
+ String prefix = getPrefix(arguments);
for (FieldDescription field : arguments.fields().values()) {
for (String alias : field.getAliases())
- aliases.put(alias,new CompoundName(prefix+field.getName()));
+ aliases.put(alias, new CompoundName(prefix+field.getName()));
}
}
private static String getPrefix(QueryProfileType type) {
@@ -294,7 +293,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
startTime = System.currentTimeMillis();
if (queryProfile != null) {
// Move all request parameters to the query profile just to validate that the parameter settings are legal
- Properties queryProfileProperties=new QueryProfileProperties(queryProfile);
+ Properties queryProfileProperties = new QueryProfileProperties(queryProfile);
properties().chain(queryProfileProperties);
// TODO: Just checking legality rather than actually setting would be faster
setPropertiesFromRequestMap(requestMap, properties()); // Adds errors to the query for illegal set attempts
@@ -360,9 +359,9 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
* (if any) set it to properties().
*/
private void setFrom(Properties originalProperties,QueryProfileType arguments,Map<String,String> context) {
- String prefix=getPrefix(arguments);
+ String prefix = getPrefix(arguments);
for (FieldDescription field : arguments.fields().values()) {
- String fullName=prefix + field.getName();
+ String fullName = prefix + field.getName();
if (field.getType() == FieldType.genericQueryProfileType) {
for (Map.Entry<String, Object> entry : originalProperties.listProperties(fullName,context).entrySet()) {
try {
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" =&gt; "a.d-value","e" =&gt; "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 =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "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 =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "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 =&gt; "a.d-value" ,a.e =&gt; "a.e-value", b.d =&gt; "b.d-value", then calling listValues("a")
* will return {"d" =&gt; "a.d-value","e" =&gt; "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 + "'");
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
index f6d30ee57e2..1422194ebdd 100644
--- a/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/properties/QueryProperties.java
@@ -24,37 +24,33 @@ import java.util.Map;
*/
public class QueryProperties extends Properties {
- private static final String MODEL_PREFIX = Model.MODEL + ".";
- private static final String RANKING_PREFIX = Ranking.RANKING + ".";
- private static final String PRESENTATION_PREFIX = Presentation.PRESENTATION + ".";
-
public static final CompoundName[] PER_SOURCE_QUERY_PROPERTIES = new CompoundName[] {
- new CompoundName(MODEL_PREFIX + Model.QUERY_STRING),
- new CompoundName(MODEL_PREFIX + Model.TYPE),
- new CompoundName(MODEL_PREFIX + Model.FILTER),
- new CompoundName(MODEL_PREFIX + Model.DEFAULT_INDEX),
- new CompoundName(MODEL_PREFIX + Model.LANGUAGE),
- new CompoundName(MODEL_PREFIX + Model.ENCODING),
- new CompoundName(MODEL_PREFIX + Model.SOURCES),
- new CompoundName(MODEL_PREFIX + Model.SEARCH_PATH),
- new CompoundName(MODEL_PREFIX + Model.RESTRICT),
- new CompoundName(RANKING_PREFIX + Ranking.LOCATION),
- new CompoundName(RANKING_PREFIX + Ranking.PROFILE),
- new CompoundName(RANKING_PREFIX + Ranking.SORTING),
- new CompoundName(RANKING_PREFIX + Ranking.FRESHNESS),
- new CompoundName(RANKING_PREFIX + Ranking.QUERYCACHE),
- new CompoundName(RANKING_PREFIX + Ranking.LIST_FEATURES),
- new CompoundName(PRESENTATION_PREFIX + Presentation.BOLDING),
- new CompoundName(PRESENTATION_PREFIX + Presentation.SUMMARY),
- new CompoundName(PRESENTATION_PREFIX + Presentation.REPORT_COVERAGE),
- new CompoundName(PRESENTATION_PREFIX + Presentation.FORMAT),
- new CompoundName(PRESENTATION_PREFIX + Presentation.SUMMARY_FIELDS),
Query.HITS,
Query.OFFSET,
Query.TRACE_LEVEL,
Query.TIMEOUT,
Query.NO_CACHE,
- Query.GROUPING_SESSION_CACHE };
+ Query.GROUPING_SESSION_CACHE,
+ CompoundName.fromComponents(Model.MODEL, Model.QUERY_STRING),
+ CompoundName.fromComponents(Model.MODEL, Model.TYPE),
+ CompoundName.fromComponents(Model.MODEL, Model.FILTER),
+ CompoundName.fromComponents(Model.MODEL, Model.DEFAULT_INDEX),
+ CompoundName.fromComponents(Model.MODEL, Model.LANGUAGE),
+ CompoundName.fromComponents(Model.MODEL, Model.ENCODING),
+ CompoundName.fromComponents(Model.MODEL, Model.SOURCES),
+ CompoundName.fromComponents(Model.MODEL, Model.SEARCH_PATH),
+ CompoundName.fromComponents(Model.MODEL, Model.RESTRICT),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.LOCATION),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.PROFILE),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.SORTING),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.FRESHNESS),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.QUERYCACHE),
+ CompoundName.fromComponents(Ranking.RANKING, Ranking.LIST_FEATURES),
+ CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.BOLDING),
+ CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.SUMMARY),
+ CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.REPORT_COVERAGE),
+ CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.FORMAT),
+ CompoundName.fromComponents(Presentation.PRESENTATION, Presentation.SUMMARY_FIELDS)};
private Query query;
private final CompiledQueryProfileRegistry profileRegistry;
@@ -73,7 +69,7 @@ public class QueryProperties extends Properties {
@Override
public Object get(CompoundName key, Map<String,String> context,
com.yahoo.processing.request.Properties substitution) {
- if (key.size()==2 && key.first().equals(Model.MODEL)) {
+ if (key.size() == 2 && key.first().equals(Model.MODEL)) {
Model model = query.getModel();
if (key.last().equals(Model.QUERY_STRING)) return model.getQueryString();
if (key.last().equals(Model.TYPE)) return model.getType();
@@ -87,7 +83,7 @@ public class QueryProperties extends Properties {
}
else if (key.first().equals(Ranking.RANKING)) {
Ranking ranking = query.getRanking();
- if (key.size()==2) {
+ if (key.size() == 2) {
if (key.last().equals(Ranking.LOCATION)) return ranking.getLocation();
if (key.last().equals(Ranking.PROFILE)) return ranking.getProfile();
if (key.last().equals(Ranking.SORTING)) return ranking.getSorting();
@@ -156,7 +152,7 @@ public class QueryProperties extends Properties {
if (key.toString().equals(Ranking.RANKING)) return query.getRanking();
if (key.toString().equals(Presentation.PRESENTATION)) return query.getPresentation();
}
- return super.get(key,context,substitution);
+ return super.get(key, context, substitution);
}
@SuppressWarnings("deprecation")
@@ -298,6 +294,21 @@ public class QueryProperties extends Properties {
}
}
+ @Override
+ public Map<String, Object> listProperties(CompoundName prefix,
+ Map<String,String> context,
+ com.yahoo.processing.request.Properties substitution) {
+ Map<String, Object> properties = super.listProperties(prefix, context, substitution);
+ for (CompoundName queryProperty : PER_SOURCE_QUERY_PROPERTIES) {
+ if (queryProperty.hasPrefix(prefix)) {
+ Object value = this.get(queryProperty, context, substitution);
+ if (value != null)
+ properties.put(queryProperty.toString(), value);
+ }
+ }
+ return properties;
+ }
+
private void setRankingFeature(Query query, String key, Object value) {
if (value instanceof Tensor)
query.getRanking().getFeatures().put(key, (Tensor)value);
diff --git a/container-search/src/main/java/com/yahoo/search/query/properties/RequestContextProperties.java b/container-search/src/main/java/com/yahoo/search/query/properties/RequestContextProperties.java
index 3627b0d6951..ee09521fa74 100644
--- a/container-search/src/main/java/com/yahoo/search/query/properties/RequestContextProperties.java
+++ b/container-search/src/main/java/com/yahoo/search/query/properties/RequestContextProperties.java
@@ -15,27 +15,27 @@ import java.util.Map;
*/
public class RequestContextProperties extends Properties {
- private final Map<String,String> requestMap;
+ private final Map<String, String> requestMap;
public RequestContextProperties(Map<String, String> properties) {
- this.requestMap=properties;
+ this.requestMap = properties;
}
@Override
public Object get(CompoundName name,Map<String,String> context,
com.yahoo.processing.request.Properties substitution) {
- return super.get(name,context==null ? requestMap : context,substitution);
+ return super.get(name, context == null ? requestMap : context, substitution);
}
@Override
public void set(CompoundName name,Object value,Map<String,String> context) {
- super.set(name,value,context==null ? requestMap : context);
+ super.set(name, value, context == null ? requestMap : context);
}
@Override
public Map<String, Object> listProperties(CompoundName path,Map<String,String> context,
com.yahoo.processing.request.Properties substitution) {
- return super.listProperties(path,context==null ? requestMap : context,substitution);
+ return super.listProperties(path, context == null ? requestMap : context, substitution);
}
}
diff --git a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
index bc07ad7bdbd..fb3f2acfadd 100644
--- a/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
+++ b/container-search/src/main/java/com/yahoo/search/query/ranking/Matching.java
@@ -13,6 +13,7 @@ import java.util.Objects;
* @author baldersheim
*/
public class Matching implements Cloneable {
+
/** The type representing the property arguments consumed by this */
private static final QueryProfileType argumentType;
@@ -32,6 +33,7 @@ public class Matching implements Cloneable {
argumentType.addField(new FieldDescription(MINHITSPERTHREAD, "integer"));
argumentType.freeze();
}
+
public static QueryProfileType getArgumentType() { return argumentType; }
public Double termwiseLimit = null;