diff options
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/processing/DictionaryProcessor.java')
-rw-r--r-- | config-model/src/main/java/com/yahoo/schema/processing/DictionaryProcessor.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/processing/DictionaryProcessor.java b/config-model/src/main/java/com/yahoo/schema/processing/DictionaryProcessor.java new file mode 100644 index 00000000000..3209fd1703d --- /dev/null +++ b/config-model/src/main/java/com/yahoo/schema/processing/DictionaryProcessor.java @@ -0,0 +1,54 @@ +// 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.document.NumericDataType; +import com.yahoo.document.PrimitiveDataType; +import com.yahoo.schema.RankProfileRegistry; +import com.yahoo.schema.Schema; +import com.yahoo.schema.document.Attribute; +import com.yahoo.schema.document.Case; +import com.yahoo.schema.document.Dictionary; +import com.yahoo.schema.document.SDField; +import com.yahoo.vespa.model.container.search.QueryProfiles; + +/** + * Propagates dictionary settings from field level to attribute level. + * Only applies to numeric fields with fast-search enabled. + * + * @author baldersheim + */ +public class DictionaryProcessor extends Processor { + public DictionaryProcessor(Schema schema, DeployLogger deployLogger, RankProfileRegistry rankProfileRegistry, QueryProfiles queryProfiles) { + super(schema, deployLogger, rankProfileRegistry, queryProfiles); + } + @Override + public void process(boolean validate, boolean documentsOnly) { + for (SDField field : schema.allConcreteFields()) { + Attribute attribute = field.getAttribute(); + if (attribute == null) continue; + attribute.setCase(field.getMatching().getCase()); + Dictionary dictionary = field.getDictionary(); + if (dictionary == null) continue; + if (attribute.getDataType().getPrimitiveType() instanceof NumericDataType ) { + if (attribute.isFastSearch()) { + attribute.setDictionary(dictionary); + } else { + fail(schema, field, "You must specify 'attribute:fast-search' to allow dictionary control"); + } + } else if (attribute.getDataType().getPrimitiveType() == PrimitiveDataType.STRING) { + attribute.setDictionary(dictionary); + if (dictionary.getType() == Dictionary.Type.HASH) { + if (dictionary.getMatch() != Case.CASED) { + fail(schema, field, "hash dictionary require cased match"); + } + } + if (! dictionary.getMatch().equals(attribute.getCase())) { + fail(schema, field, "Dictionary casing '" + dictionary.getMatch() + "' does not match field match casing '" + attribute.getCase() + "'"); + } + } else { + fail(schema, field, "You can only specify 'dictionary:' for numeric or string fields"); + } + } + } +} |