summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-04-27 13:45:41 +0200
committerJon Bratseth <bratseth@gmail.com>2022-04-27 13:45:41 +0200
commit66c9edce7bbe11cb99c636e433feb2085f8d2e8a (patch)
treec47eb08e387a8dda2a6d5748ccdb5eb8c083997f /container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java
parent1c38c6e29a59eff80396f4a367245d6694f87168 (diff)
Use an already exported package
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java')
-rw-r--r--container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java50
1 files changed, 50 insertions, 0 deletions
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
new file mode 100644
index 00000000000..84ed9ae8e3d
--- /dev/null
+++ b/container-search/src/main/java/com/yahoo/search/schema/SchemaInfoConfigurer.java
@@ -0,0 +1,50 @@
+// 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.yahoo.container.QrSearchersConfig;
+import com.yahoo.search.config.SchemaInfoConfig;
+import com.yahoo.tensor.TensorType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * Translation between schema info configuration and schema objects.
+ *
+ * @author bratseth
+ */
+class SchemaInfoConfigurer {
+
+ static List<Schema> toSchemas(SchemaInfoConfig schemaInfoConfig) {
+ return schemaInfoConfig.schema().stream().map(config -> toSchema(config)).collect(Collectors.toList());
+ }
+
+ 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());
+ profileBuilder.setHasRankFeatures(profileConfig.hasRankFeatures());
+ for (var inputConfig : profileConfig.input())
+ profileBuilder.addInput(inputConfig.name(), TensorType.fromSpec(inputConfig.type()));
+ builder.add(profileBuilder.build());
+ }
+ return builder.build();
+ }
+
+ static Map<String, List<String>> toClusters(QrSearchersConfig config) {
+ Map<String, List<String>> clusters = new HashMap<>();
+ for (int i = 0; i < config.searchcluster().size(); ++i) {
+ List<String> schemas = new ArrayList<>();
+ String clusterName = config.searchcluster(i).name();
+ for (int j = 0; j < config.searchcluster(i).searchdef().size(); ++j)
+ schemas.add(config.searchcluster(i).searchdef(j));
+ clusters.put(clusterName, schemas);
+ }
+ return clusters;
+ }
+
+}