aboutsummaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/Query.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/Query.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/Query.java53
1 files changed, 34 insertions, 19 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 74091d9978c..354881c763b 100644
--- a/container-search/src/main/java/com/yahoo/search/Query.java
+++ b/container-search/src/main/java/com/yahoo/search/Query.java
@@ -13,6 +13,7 @@ import com.yahoo.prelude.fastsearch.DocumentDatabase;
import com.yahoo.prelude.query.Highlight;
import com.yahoo.prelude.query.textualrepresentation.TextualQueryRepresentation;
import com.yahoo.processing.request.CompoundName;
+import com.yahoo.search.config.SchemaInfo;
import com.yahoo.search.dispatch.Dispatcher;
import com.yahoo.search.dispatch.rpc.ProtobufSerialization;
import com.yahoo.search.federation.FederationSearcher;
@@ -45,6 +46,7 @@ import com.yahoo.search.query.properties.QueryProperties;
import com.yahoo.search.query.properties.QueryPropertyAliases;
import com.yahoo.search.query.properties.RankProfileInputProperties;
import com.yahoo.search.query.properties.RequestContextProperties;
+import com.yahoo.search.query.ranking.RankFeatures;
import com.yahoo.search.yql.NullItemException;
import com.yahoo.search.yql.VespaSerializer;
import com.yahoo.search.yql.YqlParser;
@@ -58,6 +60,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 +157,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 --------------------------------
@@ -177,7 +179,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** The ranking requested in this query */
private Ranking ranking = new Ranking(this);
- /** The query query and/or query program declaration */
+ /** The query and/or query program declaration */
private Model model = new Model(this);
/** How results of this query should be presented */
@@ -212,6 +214,8 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
argumentType = new QueryProfileType("native");
argumentType.setBuiltin(true);
+ // Note: Order here matters as fields are set in this order, and rank feature conversion depends
+ // on other fields already being set (see RankProfileInputProperties)
argumentType.addField(new FieldDescription(OFFSET.toString(), "integer", "offset start"));
argumentType.addField(new FieldDescription(HITS.toString(), "integer", "hits count"));
argumentType.addField(new FieldDescription(QUERY_PROFILE.toString(), "string"));
@@ -223,11 +227,11 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
argumentType.addField(new FieldDescription(TIMEOUT.toString(), "string", "timeout"));
argumentType.addField(new FieldDescription(FederationSearcher.SOURCENAME.toString(),"string"));
argumentType.addField(new FieldDescription(FederationSearcher.PROVIDERNAME.toString(),"string"));
- argumentType.addField(new FieldDescription(Presentation.PRESENTATION, new QueryProfileFieldType(Presentation.getArgumentType())));
- argumentType.addField(new FieldDescription(Ranking.RANKING, new QueryProfileFieldType(Ranking.getArgumentType())));
argumentType.addField(new FieldDescription(Model.MODEL, new QueryProfileFieldType(Model.getArgumentType())));
argumentType.addField(new FieldDescription(Select.SELECT, new QueryProfileFieldType(Select.getArgumentType())));
argumentType.addField(new FieldDescription(Dispatcher.DISPATCH, new QueryProfileFieldType(Dispatcher.getArgumentType())));
+ argumentType.addField(new FieldDescription(Ranking.RANKING, new QueryProfileFieldType(Ranking.getArgumentType())));
+ argumentType.addField(new FieldDescription(Presentation.PRESENTATION, new QueryProfileFieldType(Presentation.getArgumentType())));
argumentType.freeze();
}
public static QueryProfileType getArgumentType() { return argumentType; }
@@ -259,9 +263,9 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
public static void addNativeQueryProfileTypesTo(QueryProfileTypeRegistry registry) {
// Add modifiable copies to allow query profile types in this to add to these
registry.register(Query.getArgumentType().unfrozen());
- registry.register(Ranking.getArgumentType().unfrozen());
registry.register(Model.getArgumentType().unfrozen());
registry.register(Select.getArgumentType().unfrozen());
+ registry.register(Ranking.getArgumentType().unfrozen());
registry.register(Presentation.getArgumentType().unfrozen());
registry.register(DefaultProperties.argumentType.unfrozen());
}
@@ -271,7 +275,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
ImmutableList.copyOf(namesUnder(CompoundName.empty, Query.getArgumentType()));
private static List<CompoundName> namesUnder(CompoundName prefix, QueryProfileType type) {
- if ( type == null) return Collections.emptyList(); // Names not known statically
+ if (type == null) return Collections.emptyList(); // Names not known statically
List<CompoundName> names = new ArrayList<>();
for (Map.Entry<String, FieldDescription> field : type.fields().entrySet()) {
if (field.getValue().getType() instanceof QueryProfileFieldType) {
@@ -339,7 +343,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
public Query(HttpRequest request, Map<String, String> requestMap, CompiledQueryProfile queryProfile) {
super(new QueryPropertyAliases(propertyAliases));
this.httpRequest = request;
- init(requestMap, queryProfile, Embedder.throwsOnUse.asMap(), ZoneInfo.defaultInfo());
+ init(requestMap, queryProfile, Embedder.throwsOnUse.asMap(), ZoneInfo.defaultInfo(), SchemaInfo.empty());
}
// TODO: Deprecate most constructors above here
@@ -349,23 +353,26 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
builder.getRequestMap(),
builder.getQueryProfile(),
builder.getEmbedders(),
- builder.getZoneInfo());
+ builder.getZoneInfo(),
+ builder.getSchemaInfo());
}
private Query(HttpRequest request,
Map<String, String> requestMap,
CompiledQueryProfile queryProfile,
Map<String, Embedder> embedders,
- ZoneInfo zoneInfo) {
+ ZoneInfo zoneInfo,
+ SchemaInfo schemaInfo) {
super(new QueryPropertyAliases(propertyAliases));
this.httpRequest = request;
- init(requestMap, queryProfile, embedders, zoneInfo);
+ init(requestMap, queryProfile, embedders, zoneInfo, schemaInfo);
}
private void init(Map<String, String> requestMap,
CompiledQueryProfile queryProfile,
Map<String, Embedder> embedders,
- ZoneInfo zoneInfo) {
+ ZoneInfo zoneInfo,
+ SchemaInfo schemaInfo) {
startTime = httpRequest.getJDiscRequest().creationTime(TimeUnit.MILLISECONDS);
if (queryProfile != null) {
// Move all request parameters to the query profile
@@ -374,7 +381,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
setPropertiesFromRequestMap(requestMap, properties(), true);
// Create the full chain
- properties().chain(new RankProfileInputProperties(this))
+ properties().chain(new RankProfileInputProperties(schemaInfo, this, embedders))
.chain(new QueryProperties(this, queryProfile.getRegistry(), embedders))
.chain(new ModelObjectMap())
.chain(new RequestContextProperties(requestMap, zoneInfo))
@@ -395,7 +402,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
}
else { // bypass these complications if there is no query profile to get values from and validate against
properties().
- chain(new RankProfileInputProperties(this)).
+ chain(new RankProfileInputProperties(schemaInfo, this, embedders)).
chain(new QueryProperties(this, CompiledQueryProfileRegistry.empty, embedders)).
chain(new PropertyMap()).
chain(new DefaultProperties());
@@ -462,13 +469,13 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
/** 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);
-
for (var entry : requestMap.entrySet()) {
if (ignoreSelect && entry.getKey().equals(Select.SELECT)) continue;
+ if (RankFeatures.isFeatureName(entry.getKey())) continue; // Set these last
+ properties.set(entry.getKey(), entry.getValue(), requestMap);
+ }
+ for (var entry : requestMap.entrySet()) {
+ if ( ! RankFeatures.isFeatureName(entry.getKey())) continue;
properties.set(entry.getKey(), entry.getValue(), requestMap);
}
}
@@ -1142,6 +1149,7 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
private CompiledQueryProfile queryProfile = null;
private Map<String, Embedder> embedders = Embedder.throwsOnUse.asMap();
private ZoneInfo zoneInfo = ZoneInfo.defaultInfo();
+ private SchemaInfo schemaInfo = SchemaInfo.empty();
public Builder setRequest(String query) {
request = HttpRequest.createTestRequest(query, com.yahoo.jdisc.http.HttpRequest.Method.GET);
@@ -1204,6 +1212,13 @@ public class Query extends com.yahoo.processing.Request implements Cloneable {
public ZoneInfo getZoneInfo() { return zoneInfo; }
+ public Builder setSchemaInfo(SchemaInfo schemaInfo) {
+ this.schemaInfo = schemaInfo;
+ return this;
+ }
+
+ public SchemaInfo getSchemaInfo() { return schemaInfo; }
+
/** Creates a new query from this builder. No properties are required to before calling this. */
public Query build() { return new Query(this); }