diff options
author | Jon Bratseth <bratseth@gmail.com> | 2022-05-03 20:22:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 20:22:43 +0200 |
commit | dde286759cc3384f07b957364d3c9666aff60896 (patch) | |
tree | fa9b6fe4f2caef38b3536f92ceb703f49afc713c /container-search/src/main/java/com/yahoo/search/schema | |
parent | de8e6f7128dc6489800eae8ce8cdcc6e3414475e (diff) |
Revert "Use schema-info"
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/schema')
5 files changed, 19 insertions, 218 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 deleted file mode 100644 index 12037ee6633..00000000000 --- a/container-search/src/main/java/com/yahoo/search/schema/DocumentSummary.java +++ /dev/null @@ -1,160 +0,0 @@ -// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -package com.yahoo.search.schema; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; - -/** - * A document summary definition: Defines the schema on which a document hit may be - * represented in a Result. - * - * @author bratseth - */ -public class DocumentSummary { - - private final String name; - private final List<Field> fields; - private final boolean dynamic; - - private DocumentSummary(Builder builder) { - this.name = builder.name; - this.fields = List.copyOf(builder.fields); - this.dynamic = builder.dynamic; - } - - public String name() { return name; } - public List<Field> fields() { return fields; } - - /** Returns whether this contains fields which are generated dynamically from the query and field data. */ - public boolean isDynamic() { return dynamic; } - - @Override - public boolean equals(Object o) { - if (o == this) return true; - if ( ! (o instanceof DocumentSummary)) return false; - var other = (DocumentSummary)o; - if ( ! other.name.equals(this.name)) return false; - if ( other.dynamic != this.dynamic) return false; - if ( ! other.fields.equals(this.fields)) return false; - return true; - } - - @Override - public int hashCode() { - return Objects.hash(name, dynamic, fields); - } - - @Override - public String toString() { - return "document summary '" + name + "'"; - } - - public static class Builder { - - private final String name; - private final List<Field> fields = new ArrayList<>(); - private boolean dynamic; - - public Builder(String name) { - this.name = name; - } - - public Builder add(Field field) { - fields.add(field); - return this; - } - - public Builder setDynamic(boolean dynamic) { - this.dynamic = dynamic; - return this; - } - - public DocumentSummary build() { return new DocumentSummary(this); } - - } - - public static class Field { - - public enum Type { - bool, - byteType("byte"), - shortType("short"), - integer, - int64, - float16, - floatType("float"), - doubleType("double"), - string, - data, - raw, - longstring, - longdata, - jsonstring, - featuredata, - xmlstring, - tensor; - - private final String name; - - Type() { - this(null); - } - - Type(String name) { - this.name = name; - } - - /** Use this, not name() to retrieve the string value of this. */ - public String asString() { - return name != null ? name : name(); - } - - @Override - public String toString() { return asString(); } - - public static Type fromString(String name) { - return Arrays.stream(Type.values()).filter(t -> name.equals(t.asString())).findAny().orElseThrow(); - } - - } - - private final String name; - private final Type type; - - public Field(String name, String type) { - this(name, Type.fromString(type)); - } - - public Field(String name, Type type) { - this.name = name; - this.type = type; - } - - public String name() { return name; } - public Type type() { return type; } - - @Override - public boolean equals(Object o) { - if (o == this) return true; - if ( ! (o instanceof Field)) return false; - var other = (Field)o; - if ( ! other.name.equals(this.name)) return false; - if ( other.type != this.type) return false; - return true; - } - - @Override - public int hashCode() { - return Objects.hash(name, type); - } - - @Override - public String toString() { - return "summary field '" + name + "' " + type; - } - - } - -} diff --git a/container-search/src/main/java/com/yahoo/search/schema/RankProfile.java b/container-search/src/main/java/com/yahoo/search/schema/RankProfile.java index 39d4a389e6f..8267e5c937b 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/RankProfile.java +++ b/container-search/src/main/java/com/yahoo/search/schema/RankProfile.java @@ -3,9 +3,7 @@ package com.yahoo.search.schema; import com.yahoo.tensor.TensorType; -import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; @@ -25,7 +23,7 @@ public class RankProfile { this.name = builder.name; this.hasSummaryFeatures = builder.hasSummaryFeatures; this.hasRankFeatures = builder.hasRankFeatures; - this.inputs = Collections.unmodifiableMap(builder.inputs); + this.inputs = Map.copyOf(builder.inputs); } public String name() { return name; } @@ -66,7 +64,7 @@ public class RankProfile { private final String name; private boolean hasSummaryFeatures = true; private boolean hasRankFeatures = true; - private final Map<String, TensorType> inputs = new LinkedHashMap<>(); + private final Map<String, TensorType> inputs = new HashMap<>(); public Builder(String name) { this.name = Objects.requireNonNull(name); diff --git a/container-search/src/main/java/com/yahoo/search/schema/Schema.java b/container-search/src/main/java/com/yahoo/search/schema/Schema.java index 2ab5a30fbd7..b66e6ce957a 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/Schema.java +++ b/container-search/src/main/java/com/yahoo/search/schema/Schema.java @@ -3,9 +3,7 @@ package com.yahoo.search.schema; import com.yahoo.api.annotations.Beta; -import java.util.Collections; import java.util.HashMap; -import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; @@ -21,17 +19,14 @@ public class Schema { private final String name; private final Map<String, RankProfile> rankProfiles; - private final Map<String, DocumentSummary> documentSummaries; private Schema(Builder builder) { this.name = builder.name; - this.rankProfiles = Collections.unmodifiableMap(builder.rankProfiles); - this.documentSummaries = Collections.unmodifiableMap(builder.documentSummaries); + this.rankProfiles = Map.copyOf(builder.rankProfiles); } public String name() { return name; } public Map<String, RankProfile> rankProfiles() { return rankProfiles; } - public Map<String, DocumentSummary> documentSummaries() { return documentSummaries; } @Override public boolean equals(Object o) { @@ -40,13 +35,12 @@ public class Schema { Schema other = (Schema)o; if ( ! other.name.equals(this.name)) return false; if ( ! other.rankProfiles.equals(this.rankProfiles)) return false; - if ( ! other.documentSummaries.equals(this.documentSummaries)) return false; return true; } @Override public int hashCode() { - return Objects.hash(name, rankProfiles, documentSummaries); + return Objects.hash(name, rankProfiles); } @Override @@ -57,20 +51,14 @@ public class Schema { public static class Builder { private final String name; - private final Map<String, RankProfile> rankProfiles = new LinkedHashMap<>(); - private final Map<String, DocumentSummary> documentSummaries = new LinkedHashMap<>(); + private final Map<String, RankProfile> rankProfiles = new HashMap<>(); public Builder(String name) { this.name = Objects.requireNonNull(name); } public Builder add(RankProfile profile) { - rankProfiles.put(profile.name(), profile); - return this; - } - - public Builder add(DocumentSummary documentSummary) { - documentSummaries.put(documentSummary.name(), documentSummary); + rankProfiles.put(profile.name(), Objects.requireNonNull(profile)); return this; } diff --git a/container-search/src/main/java/com/yahoo/search/schema/SchemaInfo.java b/container-search/src/main/java/com/yahoo/search/schema/SchemaInfo.java index 7bd66445512..4daf110fc54 100644 --- a/container-search/src/main/java/com/yahoo/search/schema/SchemaInfo.java +++ b/container-search/src/main/java/com/yahoo/search/schema/SchemaInfo.java @@ -2,17 +2,13 @@ package com.yahoo.search.schema; import com.yahoo.api.annotations.Beta; -import com.yahoo.component.annotation.Inject; import com.yahoo.container.QrSearchersConfig; import com.yahoo.search.Query; import com.yahoo.search.config.IndexInfoConfig; import com.yahoo.search.config.SchemaInfoConfig; import com.yahoo.tensor.TensorType; -import java.util.Collection; -import java.util.Collections; import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -43,12 +39,11 @@ public class SchemaInfo { private static final SchemaInfo empty = new SchemaInfo(List.of(), Map.of()); - private final Map<String, Schema> schemas; + private final List<Schema> schemas; /** The schemas contained in each content cluster indexed by cluster name */ private final Map<String, List<String>> clusters; - @Inject public SchemaInfo(IndexInfoConfig indexInfo, // will be used in the future SchemaInfoConfig schemaInfoConfig, QrSearchersConfig qrSearchersConfig) { @@ -56,14 +51,12 @@ public class SchemaInfo { } public SchemaInfo(List<Schema> schemas, Map<String, List<String>> clusters) { - Map<String, Schema> schemaMap = new LinkedHashMap<>(); - schemas.forEach(schema -> schemaMap.put(schema.name(), schema)); - this.schemas = Collections.unmodifiableMap(schemaMap); - this.clusters = Collections.unmodifiableMap(clusters); + this.schemas = List.copyOf(schemas); + this.clusters = Map.copyOf(clusters); } - /** Returns all schemas configured in this application, indexed by schema name. */ - public Map<String, Schema> schemas() { return schemas; } + /** Returns all schemas configured in this application. */ + public List<Schema> schemas() { return schemas; } public Session newSession(Query query) { return new Session(query.getModel().getSources(), query.getModel().getRestrict(), clusters, schemas); @@ -87,13 +80,13 @@ public class SchemaInfo { /** The schema information resolved to be relevant to this session. */ public static class Session { - private final Collection<Schema> schemas; + private final List<Schema> schemas; private Session(Set<String> sources, Set<String> restrict, Map<String, List<String>> clusters, - Map<String, Schema> candidates) { - this.schemas = resolveSchemas(sources, restrict, clusters, candidates.values()); + List<Schema> candidates) { + this.schemas = resolveSchemas(sources, restrict, clusters, candidates); } /** @@ -103,10 +96,10 @@ public class SchemaInfo { * * @return the possibly empty list of schemas matching the arguments */ - private static Collection<Schema> resolveSchemas(Set<String> sources, - Set<String> restrict, - Map<String, List<String>> clusters, - Collection<Schema> candidates) { + private static List<Schema> resolveSchemas(Set<String> sources, + Set<String> restrict, + Map<String, List<String>> clusters, + List<Schema> candidates) { if (sources.isEmpty()) return restrict.isEmpty() ? candidates : keep(restrict, candidates); @@ -121,7 +114,7 @@ public class SchemaInfo { return restrict.isEmpty() ? candidates : keep(restrict, candidates); } - private static List<Schema> keep(Set<String> names, Collection<Schema> schemas) { + private static List<Schema> keep(Set<String> names, List<Schema> schemas) { return schemas.stream().filter(schema -> names.contains(schema.name())).collect(Collectors.toList()); } 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..84ed9ae8e3d 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; @@ -30,7 +24,6 @@ class SchemaInfoConfigurer { static Schema toSchema(SchemaInfoConfig.Schema schemaInfoConfig) { Schema.Builder builder = new Schema.Builder(schemaInfoConfig.name()); - for (var profileConfig : schemaInfoConfig.rankprofile()) { RankProfile.Builder profileBuilder = new RankProfile.Builder(profileConfig.name()); profileBuilder.setHasSummaryFeatures(profileConfig.hasSummaryFeatures()); @@ -39,17 +32,6 @@ class SchemaInfoConfigurer { profileBuilder.addInput(inputConfig.name(), TensorType.fromSpec(inputConfig.type())); builder.add(profileBuilder.build()); } - - for (var summaryConfig : schemaInfoConfig.summaryclass()) { - DocumentSummary.Builder summaryBuilder = new DocumentSummary.Builder(summaryConfig.name()); - for (var field : summaryConfig.fields()) { - if (field.dynamic()) - summaryBuilder.setDynamic(true); - summaryBuilder.add(new DocumentSummary.Field(field.name(), field.type())); - } - builder.add(summaryBuilder.build()); - } - return builder.build(); } |