diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-06-16 17:04:42 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2022-06-16 17:04:42 +0200 |
commit | 32b9b81e411345bbf407aa648e80bd4b051f234f (patch) | |
tree | 7d1c1de0c9457f602e91e899444e44546f7500d1 /container-search/src/main/java/com/yahoo/search | |
parent | 5e00300349d15d4aad0df4ab0631a811df526b79 (diff) |
Remove usage of documentdbinfo, apart from schema name
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search')
4 files changed, 46 insertions, 88 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/schema/DocumentSummary.java b/container-search/src/main/java/com/yahoo/search/schema/DocumentSummary.java index 12037ee6633..0aec6b0a4f6 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/DocumentSummary.java +++ b/container-search/src/main/java/com/yahoo/search/schema/DocumentSummary.java @@ -3,7 +3,10 @@ package com.yahoo.search.schema; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Objects; /** @@ -15,17 +18,17 @@ import java.util.Objects; public class DocumentSummary { private final String name; - private final List<Field> fields; + private final Map<String, Field> fields; private final boolean dynamic; private DocumentSummary(Builder builder) { this.name = builder.name; - this.fields = List.copyOf(builder.fields); + this.fields = Collections.unmodifiableMap(builder.fields); this.dynamic = builder.dynamic; } public String name() { return name; } - public List<Field> fields() { return fields; } + public Map<String, Field> fields() { return fields; } /** Returns whether this contains fields which are generated dynamically from the query and field data. */ public boolean isDynamic() { return dynamic; } @@ -54,15 +57,20 @@ public class DocumentSummary { public static class Builder { private final String name; - private final List<Field> fields = new ArrayList<>(); + private final Map<String, Field> fields = new LinkedHashMap<>(); private boolean dynamic; public Builder(String name) { this.name = name; } + public Builder addField(String name, String type) { + fields.put(name, new Field(name, type)); + return this; + } + public Builder add(Field field) { - fields.add(field); + fields.put(field.name(), field); return this; } diff --git a/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java b/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java index c5a74ece866..ed1d25a0b35 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java +++ b/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java @@ -1,17 +1,11 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.schema; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.yahoo.container.QrSearchersConfig; -import com.yahoo.prelude.fastsearch.DocsumDefinition; -import com.yahoo.prelude.fastsearch.DocsumField; -import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig; import com.yahoo.search.config.SchemaInfoConfig; import com.yahoo.tensor.TensorType; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java index 2dfa6ef3e3a..db44e13c27e 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java +++ b/container-search/src/main/java/com/yahoo/search/yql/FieldFiller.java @@ -1,104 +1,45 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.search.yql; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Set; -import com.yahoo.api.annotations.Beta; import com.yahoo.component.chain.dependencies.After; -import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig; -import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig.Documentdb; -import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig.Documentdb.Summaryclass; -import com.yahoo.prelude.fastsearch.DocumentdbInfoConfig.Documentdb.Summaryclass.Fields; import static com.yahoo.prelude.fastsearch.VespaBackEndSearcher.SORTABLE_ATTRIBUTES_SUMMARY_CLASS; import com.yahoo.processing.request.CompoundName; import com.yahoo.search.Query; import com.yahoo.search.Result; import com.yahoo.search.Searcher; import com.yahoo.search.query.Presentation; +import com.yahoo.search.schema.DocumentSummary; +import com.yahoo.search.schema.Schema; +import com.yahoo.search.schema.SchemaInfo; import com.yahoo.search.searchchain.Execution; /** - * Ensure the fields specified in {@link Presentation#getSummaryFields()} are - * available after filling phase. + * Ensure the fields specified in {@link Presentation#getSummaryFields()} are available after filling phase. * * @author stiankri * @author Steinar Knutsen */ -@Beta @After(MinimalQueryInserter.EXTERNAL_YQL) public class FieldFiller extends Searcher { private final Set<String> intersectionOfAttributes; - private final SummaryIntersections summaryDb = new SummaryIntersections(); + private final SchemaInfo schemaInfo; public static final CompoundName FIELD_FILLER_DISABLE = new CompoundName("FieldFiller.disable"); - private static class SummaryIntersections { - private final Map<String, Map<String, Set<String>>> db = new HashMap<>(); + public FieldFiller(SchemaInfo schemaInfo) { + this.schemaInfo = schemaInfo; - void add(String dbName, Summaryclass summary) { - Map<String, Set<String>> docType = getOrCreateDocType(dbName); - Set<String> fields = new HashSet<>(summary.fields().size()); - for (Fields f : summary.fields()) { - fields.add(f.name()); - } - docType.put(summary.name(), fields); - } - - private Map<String, Set<String>> getOrCreateDocType(String dbName) { - Map<String, Set<String>> docType = db.get(dbName); - if (docType == null) { - docType = new HashMap<>(); - db.put(dbName, docType); - } - return docType; - } - - boolean hasAll(Set<String> requested, String summaryName, Set<String> restrict) { - Set<String> explicitRestriction; - Set<String> intersection = null; - - if (restrict.isEmpty()) { - explicitRestriction = db.keySet(); - } else { - explicitRestriction = restrict; - } - - for (String docType : explicitRestriction) { - Map<String, Set<String>> summaries = db.get(docType); - Set<String> summary; - - if (summaries == null) { - continue; - } - summary = summaries.get(summaryName); - if (summary == null) { - intersection = null; - break; - } - if (intersection == null) { - intersection = new HashSet<>(summary.size()); - intersection.addAll(summary); - } else { - intersection.retainAll(summary); - } - } - return intersection != null && intersection.containsAll(requested); - } - } - - public FieldFiller(DocumentdbInfoConfig config) { intersectionOfAttributes = new HashSet<>(); boolean first = true; - - for (Documentdb db : config.documentdb()) { - for (Summaryclass summary : db.summaryclass()) { + for (Schema schema : schemaInfo.schemas().values()) { + for (DocumentSummary summary : schema.documentSummaries().values()) { Set<String> attributes; if (SORTABLE_ATTRIBUTES_SUMMARY_CLASS.equals(summary.name())) { attributes = new HashSet<>(summary.fields().size()); - for (Fields f : summary.fields()) { + for (DocumentSummary.Field f : summary.fields().values()) { attributes.add(f.name()); } if (first) { @@ -108,12 +49,6 @@ public class FieldFiller extends Searcher { intersectionOfAttributes.retainAll(attributes); } } - // yes, we store attribute prefetch here as well, this is in - // case we get a query where we have a restrict parameter which - // makes filling with attribute prefetch possible even though it - // wouldn't have been possible without restricting the set of - // doctypes - summaryDb.add(db.name(), summary); } } } @@ -140,10 +75,31 @@ public class FieldFiller extends Searcher { } } else { // Yes, summaryClass may be SORTABLE_ATTRIBUTES_SUMMARY_CLASS here - if ( ! summaryDb.hasAll(summaryFields, summaryClass, result.getQuery().getModel().getRestrict())) { + if ( ! hasAll(summaryFields, summaryClass, result.getQuery().getModel().getRestrict())) { execution.fill(result, null); } } } + private boolean hasAll(Set<String> requested, String summaryName, Set<String> restrict) { + Set<String> intersection = null; + for (String schemaName : restrict.isEmpty() ? schemaInfo.schemas().keySet() : restrict) { + Schema schema = schemaInfo.schemas().get(schemaName); + if (schema == null) continue; + + DocumentSummary summary = schema.documentSummaries().get(summaryName); + if (summary == null) { + intersection = null; + break; + } + if (intersection == null) { + intersection = new HashSet<>(summary.fields().size()); + intersection.addAll(summary.fields().keySet()); + } else { + intersection.retainAll(summary.fields().keySet()); + } + } + return intersection != null && intersection.containsAll(requested); + } + } diff --git a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java index e1400e4f860..48c48748563 100644 --- a/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java +++ b/container-search/src/main/java/com/yahoo/search/yql/MinimalQueryInserter.java @@ -63,7 +63,7 @@ public class MinimalQueryInserter extends Searcher { Query query = new Query("search/?yql=select%20*%20from%20sources%20where%20title%20contains%20'xyz'"); Result result = insertQuery(query, new ParserEnvironment().setLinguistics(linguistics)); if (result != null) { - log.warning("Warmup code trigger an error. Error = " + result.toString()); + log.warning("Warmup code trigger an error. Error = " + result); return false; } if ( ! "select * from sources where title contains \"xyz\"".equals(query.yqlRepresentation())) { |