summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
commit5c24dc5c9642a8d9ed70aee4c950fd0678a1ebec (patch)
treebd9b74bf00c832456f0b83c1b2cd7010be387d68 /config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java
parentf17c4fe7de4c55f5c4ee61897eab8c2f588d8405 (diff)
Rename the 'searchdefinition' package to 'schema'
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java76
1 files changed, 76 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java b/config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java
new file mode 100644
index 00000000000..3a889085871
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/processing/MultifieldIndexHarmonizer.java
@@ -0,0 +1,76 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.processing;
+
+import com.yahoo.config.application.api.DeployLogger;
+import com.yahoo.schema.RankProfileRegistry;
+import com.yahoo.schema.Schema;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.processing.multifieldresolver.IndexCommandResolver;
+import com.yahoo.schema.processing.multifieldresolver.RankTypeResolver;
+import com.yahoo.schema.processing.multifieldresolver.StemmingResolver;
+import com.yahoo.vespa.model.container.search.QueryProfiles;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Ensures that there are no conflicting types or field settings
+ * in multifield indices, either by changing settings or by splitting
+ * conflicting fields in multiple ones with different settings.
+ *
+ * @author bratseth
+ */
+public class MultifieldIndexHarmonizer extends Processor {
+
+ /** A map from index names to a List of fields going to that index */
+ private Map<String,List<SDField>> indexToFields=new java.util.HashMap<>();
+
+ public MultifieldIndexHarmonizer(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) {
+ super(schema, deployLogger, rankProfileRegistry, queryProfiles);
+ }
+
+ @Override
+ public void process(boolean validate, boolean documentsOnly) {
+ populateIndexToFields(schema);
+ resolveAllConflicts(schema);
+ }
+
+ private void populateIndexToFields(Schema schema) {
+ for (SDField field : schema.allConcreteFields() ) {
+ if ( ! field.doesIndexing()) continue;
+ addIndexField(field.getName(), field);
+ }
+ }
+
+ private void addIndexField(String indexName,SDField field) {
+ List<SDField> fields = indexToFields.get(indexName);
+ if (fields == null) {
+ fields = new java.util.ArrayList<>();
+ indexToFields.put(indexName, fields);
+ }
+ fields.add(field);
+ }
+
+ private void resolveAllConflicts(Schema schema) {
+ for (Map.Entry<String, List<SDField>> entry : indexToFields.entrySet()) {
+ String indexName = entry.getKey();
+ List<SDField> fields = entry.getValue();
+ if (fields.size() == 1) continue; // It takes two to make a conflict
+ resolveConflicts(indexName, fields, schema);
+ }
+ }
+
+ /**
+ * Resolves all conflicts for one index
+ *
+ * @param indexName the name of the index in question
+ * @param fields all the fields indexed to this index
+ * @param schema the search definition having this
+ */
+ private void resolveConflicts(String indexName, List<SDField> fields, Schema schema) {
+ new StemmingResolver(indexName, fields, schema, deployLogger).resolve();
+ new IndexCommandResolver(indexName, fields, schema, deployLogger).resolve();
+ new RankTypeResolver(indexName, fields, schema, deployLogger).resolve();
+ }
+
+}