summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--container-core/src/main/java/com/yahoo/processing/request/CompoundName.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java27
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/Ranking.java5
-rw-r--r--container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java21
4 files changed, 43 insertions, 12 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
index d571bf583d6..efed58f4ab0 100644
--- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -285,4 +285,6 @@ public final class CompoundName {
return b.length()==0 ? "" : b.substring(0, b.length()-1);
}
+ public static CompoundName from(String name) { return new CompoundName(name); }
+
}
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 7d78012bcfd..7def8d3ab3c 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -58,6 +58,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
@@ -154,11 +155,10 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** The timeout of the query, in milliseconds */
private long timeout = defaultTimeout;
-
/** Whether this query is forbidden to access cached information */
private boolean noCache = false;
- /** Whether or not grouping should use a session cache */
+ /** Whether grouping should use a session cache */
private boolean groupingSessionCache = true;
//-------------- Generic property containers --------------------------------
@@ -459,12 +459,15 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
}
+ private static final List<CompoundName> fieldsToSetFirst = List.of(CompoundName.from("ranking.profile"),
+ CompoundName.from("model.sources"),
+ CompoundName.from("model.restrict"));
+
/** Calls properties.set on all entries in requestMap */
private void setPropertiesFromRequestMap(Map<String, String> requestMap, Properties properties, boolean ignoreSelect) {
- // Set rank profile first because it contains type information in inputs which impacts other values set
- String rankProfile = Ranking.lookupRankProfileIn(requestMap);
- if (rankProfile != null)
- properties.set(Ranking.RANKING + "." + Ranking.PROFILE, rankProfile, requestMap);
+ // Set these first because they contain type information in inputs which impacts other values set
+ for (var fieldName : fieldsToSetFirst)
+ lookupIn(requestMap, fieldName).ifPresent(value -> properties.set(fieldName, value));
for (var entry : requestMap.entrySet()) {
if (ignoreSelect && entry.getKey().equals(Select.SELECT)) continue;
@@ -472,6 +475,18 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
}
+ private Optional<String> lookupIn(Map<String, String> requestMap, CompoundName fieldName) {
+ String value = requestMap.get(fieldName.toString());
+ if (value != null) return Optional.of(value);
+ FieldDescription field = argumentType.getField(fieldName);
+ for (String alias : field.getAliases()) {
+ value = requestMap.get(alias);
+ if (value != null)
+ return Optional.of(value);
+ }
+ return Optional.empty();
+ }
+
/** Returns the properties of this query. The properties are modifiable */
@Override
public Properties properties() { return (Properties)super.properties(); }
diff --git a/container-search/src/main/java/com/yahoo/search/query/Ranking.java b/container-search/src/main/java/com/yahoo/search/query/Ranking.java
index 9f5b9a77547..94b8b5f63f1 100644
--- a/container-search/src/main/java/com/yahoo/search/query/Ranking.java
+++ b/container-search/src/main/java/com/yahoo/search/query/Ranking.java
@@ -53,8 +53,9 @@ public class Ranking implements Cloneable {
public static final String PROPERTIES = "properties";
/** For internal use only. */
- public static String lookupRankProfileIn(Map<String, String> properties) {
- return Optional.ofNullable(properties.get(RANKING + "." + PROFILE)).orElse(properties.get("ranking"));
+ public static Optional<String> lookupRankProfileIn(Map<String, String> properties) {
+ return Optional.ofNullable(Optional.ofNullable(properties.get(RANKING + "." + PROFILE))
+ .orElse(properties.get("ranking")));
}
static {
diff --git a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
index 8b6470996d5..165ec460822 100644
--- a/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
+++ b/container-search/src/main/java/com/yahoo/search/query/profile/types/QueryProfileType.java
@@ -226,7 +226,7 @@ public class QueryProfileType extends FreezableSimpleComponent {
return ((QueryProfileFieldType) fieldDescription.getType()).getQueryProfileType();
}
- /** Returns the field type of the given name under this, of null if none */
+ /** Returns the type of the given name under this, of null if none */
public FieldType getFieldType(CompoundName name) {
FieldDescription field = getField(name.first());
if (field == null) return null;
@@ -239,18 +239,31 @@ public class QueryProfileType extends FreezableSimpleComponent {
return ((QueryProfileFieldType)fieldType).getQueryProfileType().getFieldType(name.rest());
}
+ /** Returns the description of the given name under this, of null if none */
+ public FieldDescription getField(CompoundName globalName) {
+ FieldDescription field = getField(globalName.first());
+ if (field == null) return null;
+
+ if (globalName.size() == 1) return field;
+
+ FieldType fieldType = field.getType();
+ if ( ! (fieldType instanceof QueryProfileFieldType)) return null;
+
+ return ((QueryProfileFieldType)fieldType).getQueryProfileType().getField(globalName.rest());
+ }
+
/**
* Returns the description of the field with the given name in this type or an inherited type
* (depth first left to right search). Returns null if the field is not defined in this or an inherited profile.
*/
- public FieldDescription getField(String name) {
- FieldDescription field = fields.get(name);
+ public FieldDescription getField(String localName) {
+ FieldDescription field = fields.get(localName);
if ( field != null ) return field;
if ( isFrozen() ) return null; // Inherited are collapsed into this
for (QueryProfileType inheritedType : this.inherited() ) {
- field = inheritedType.getField(name);
+ field = inheritedType.getField(localName);
if (field != null) return field;
}