summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjørn Christian Seime <bjorncs@yahooinc.com>2023-04-11 15:29:43 +0200
committerBjørn Christian Seime <bjorncs@yahooinc.com>2023-04-11 15:29:43 +0200
commit724ab1e6c2852cd17ce0c0c01151309e34dcf18c (patch)
treee7fc4cc3767e2765a5fedbd736bc2f4b591359b2
parent627a6e0d83794251a03854e383c3b829c6b21aba (diff)
Revert "Move schema resolving to separate helper class"
This reverts commit 75c59aad9977f0021001f823b36b791af954b662.
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java41
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/cluster/SchemaResolver.java58
2 files changed, 33 insertions, 66 deletions
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
index f0e3e3f3e44..0bda1ce75ad 100644
--- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
@@ -1,8 +1,8 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.prelude.cluster;
-import com.yahoo.component.ComponentId;
import com.yahoo.component.annotation.Inject;
+import com.yahoo.component.ComponentId;
import com.yahoo.component.chain.dependencies.After;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.container.QrSearchersConfig;
@@ -28,6 +28,9 @@ import com.yahoo.vespa.streamingvisitors.VdsStreamingSearcher;
import com.yahoo.yolean.Exceptions;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@@ -53,7 +56,8 @@ public class ClusterSearcher extends Searcher {
private final String searchClusterName;
- private final SchemaResolver schemaResolver;
+ // The set of document types contained in this search cluster
+ private final Set<String> schemas;
private final long maxQueryTimeout; // in milliseconds
private final long maxQueryCacheTimeout; // in milliseconds
@@ -79,7 +83,7 @@ public class ClusterSearcher extends Searcher {
searchClusterName = clusterConfig.clusterName();
QrSearchersConfig.Searchcluster searchClusterConfig = getSearchClusterConfigFromClusterName(qrsConfig, searchClusterName);
this.globalPhaseRanker = searchClusterConfig.globalphase() ? globalPhaseRanker : null;
- this.schemaResolver = new SchemaResolver(documentDbConfig);
+ schemas = new LinkedHashSet<>();
maxQueryTimeout = ParameterParser.asMilliSeconds(clusterConfig.maxQueryTimeout(), DEFAULT_MAX_QUERY_TIMEOUT);
maxQueryCacheTimeout = ParameterParser.asMilliSeconds(clusterConfig.maxQueryCacheTimeout(), DEFAULT_MAX_QUERY_CACHE_TIMEOUT);
@@ -88,6 +92,9 @@ public class ClusterSearcher extends Searcher {
.com().yahoo().prelude().fastsearch().FastSearcher().docsum()
.defaultclass());
+ for (DocumentdbInfoConfig.Documentdb docDb : documentDbConfig.documentdb())
+ schemas.add(docDb.name());
+
String uniqueServerId = UUID.randomUUID().toString();
if (searchClusterConfig.indexingmode() == STREAMING) {
server = vdsCluster(uniqueServerId, searchClusterIndex,
@@ -149,7 +156,7 @@ public class ClusterSearcher extends Searcher {
/** Do not use, for internal testing purposes only. **/
ClusterSearcher(Set<String> schemas, VespaBackEndSearcher searcher, Executor executor) {
- this.schemaResolver = new SchemaResolver(schemas);
+ this.schemas = schemas;
searchClusterName = "testScenario";
maxQueryTimeout = DEFAULT_MAX_QUERY_TIMEOUT;
maxQueryCacheTimeout = DEFAULT_MAX_QUERY_CACHE_TIMEOUT;
@@ -221,9 +228,8 @@ public class ClusterSearcher extends Searcher {
}
private Result doSearch(Searcher searcher, Query query, Execution execution) {
- var schemas = schemaResolver.resolve(query, execution);
if (schemas.size() > 1) {
- return searchMultipleDocumentTypes(searcher, query, execution, schemas);
+ return searchMultipleDocumentTypes(searcher, query, execution);
} else {
String docType = schemas.iterator().next();
query.getModel().setRestrict(docType);
@@ -259,7 +265,8 @@ public class ClusterSearcher extends Searcher {
}
}
- private Result searchMultipleDocumentTypes(Searcher searcher, Query query, Execution execution, Set<String> schemas) {
+ private Result searchMultipleDocumentTypes(Searcher searcher, Query query, Execution execution) {
+ Set<String> schemas = resolveSchemas(query, execution.context().getIndexFacts());
List<Query> queries = createQueries(query, schemas);
if (queries.size() == 1) {
return perSchemaSearch(searcher, queries.get(0), execution);
@@ -293,7 +300,25 @@ public class ClusterSearcher extends Searcher {
}
Set<String> resolveSchemas(Query query, IndexFacts indexFacts) {
- return schemaResolver.resolve(query, indexFacts);
+ Set<String> restrict = query.getModel().getRestrict();
+ if (restrict == null || restrict.isEmpty()) {
+ Set<String> sources = query.getModel().getSources();
+ return (sources == null || sources.isEmpty())
+ ? schemas
+ : new HashSet<>(indexFacts.newSession(sources, Set.of(), schemas).documentTypes());
+ } else {
+ return filterValidDocumentTypes(restrict);
+ }
+ }
+
+ private Set<String> filterValidDocumentTypes(Collection<String> restrict) {
+ Set<String> retval = new LinkedHashSet<>();
+ for (String docType : restrict) {
+ if (docType != null && schemas.contains(docType)) {
+ retval.add(docType);
+ }
+ }
+ return retval;
}
private List<Query> createQueries(Query query, Set<String> docTypes) {
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/SchemaResolver.java b/container-search/src/main/java/com/yahoo/prelude/cluster/SchemaResolver.java
deleted file mode 100644
index 3a2125d1d38..00000000000
--- a/container-search/src/main/java/com/yahoo/prelude/cluster/SchemaResolver.java
+++ /dev/null
@@ -1,58 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-package com.yahoo.prelude.cluster;
-
-import com.yahoo.prelude.IndexFacts;
-import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig;
-import com.yahoo.search.Query;
-import com.yahoo.search.searchchain.Execution;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Set;
-
-/**
- * Resolves schemas from query and execution context
- *
- * @author bjorncs
- */
-class SchemaResolver {
-
- private final Set<String> schemas;
-
- SchemaResolver(DocumentdbInfoConfig cfg) {
- this(cfg.documentdb().stream().map(DocumentdbInfoConfig.Documentdb::name).toList());
- }
-
- SchemaResolver(Collection<String> schemas) {
- this.schemas = new LinkedHashSet<>(schemas);
- }
-
- Set<String> resolve(Query query, Execution execution) {
- return resolve(query, execution.context().getIndexFacts());
- }
-
- Set<String> resolve(Query query, IndexFacts indexFacts) {
- if (schemas.size() == 1) return Set.of(schemas.iterator().next());
- var restrict = query.getModel().getRestrict();
- if (restrict == null || restrict.isEmpty()) {
- Set<String> sources = query.getModel().getSources();
- return (sources == null || sources.isEmpty())
- ? schemas
- : new LinkedHashSet<>(indexFacts.newSession(sources, Set.of(), schemas).documentTypes());
- } else {
- return filterValidDocumentTypes(restrict);
- }
- }
-
- private Set<String> filterValidDocumentTypes(Collection<String> restrict) {
- Set<String> retval = new LinkedHashSet<>();
- for (String docType : restrict) {
- if (docType != null && schemas.contains(docType)) {
- retval.add(docType);
- }
- }
- return retval;
- }
-
-}