aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/schema/fieldoperation
diff options
context:
space:
mode:
Diffstat (limited to 'config-model/src/main/java/com/yahoo/schema/fieldoperation')
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/AliasOperation.java42
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/AttributeOperation.java172
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/BoldingOperation.java25
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/DictionaryOperation.java41
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java22
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperationContainer.java19
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/IdOperation.java35
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexOperation.java134
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java61
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/MatchOperation.java65
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/NormalizingOperation.java34
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/QueryCommandOperation.java25
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/RankOperation.java36
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/RankTypeOperation.java43
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/SortingOperation.java93
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/StemmingOperation.java26
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/StructFieldOperation.java56
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldLongOperation.java70
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldOperation.java46
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldShortOperation.java32
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryToOperation.java41
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightOperation.java25
-rw-r--r--config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightedSetOperation.java70
23 files changed, 1213 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/AliasOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/AliasOperation.java
new file mode 100644
index 00000000000..b5648dde4fc
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/AliasOperation.java
@@ -0,0 +1,42 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class AliasOperation implements FieldOperation {
+
+ private String aliasedName;
+ private String alias;
+
+ public AliasOperation(String aliasedName, String alias) {
+ this.aliasedName = aliasedName;
+ this.alias = alias;
+ }
+
+ public String getAliasedName() {
+ return aliasedName;
+ }
+
+ public void setAliasedName(String aliasedName) {
+ this.aliasedName = aliasedName;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+ public void apply(SDField field) {
+ if (aliasedName == null) {
+ aliasedName = field.getName();
+ }
+ field.getAliasToName().put(alias, aliasedName);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/AttributeOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/AttributeOperation.java
new file mode 100644
index 00000000000..3983137129d
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/AttributeOperation.java
@@ -0,0 +1,172 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.Attribute;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.tensor.TensorType;
+
+import java.util.Locale;
+import java.util.Optional;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class AttributeOperation implements FieldOperation, FieldOperationContainer {
+
+ private final String name;
+ private Boolean huge;
+ private Boolean fastSearch;
+ private Boolean fastAccess;
+ private Boolean mutable;
+ private Boolean paged;
+ private Boolean enableBitVectors;
+ private Boolean enableOnlyBitVector;
+ //TODO: Remember sorting!!
+ private boolean doAlias = false;
+ private String alias;
+ private String aliasedName;
+ private Optional<TensorType> tensorType = Optional.empty();
+ private Optional<String> distanceMetric = Optional.empty();
+
+ public AttributeOperation(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public void addOperation(FieldOperation op) {
+ //TODO: Implement this method:
+
+ }
+
+ @Override
+ public void applyOperations(SDField field) {
+ //TODO: Implement this method:
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public Boolean getHuge() {
+ return huge;
+ }
+
+ public void setHuge(Boolean huge) {
+ this.huge = huge;
+ }
+
+ public Boolean getFastSearch() {
+ return fastSearch;
+ }
+
+ public void setFastSearch(Boolean fastSearch) {
+ this.fastSearch = fastSearch;
+ }
+
+ public Boolean getFastAccess() {
+ return fastAccess;
+ }
+
+ public void setFastAccess(Boolean fastAccess) {
+ this.fastAccess = fastAccess;
+ }
+ public void setMutable(Boolean mutable) {
+ this.mutable = mutable;
+ }
+ public void setPaged(Boolean paged) {
+ this.paged = paged;
+ }
+
+ public Boolean getEnableBitVectors() {
+ return enableBitVectors;
+ }
+
+ public void setEnableBitVectors(Boolean enableBitVectors) {
+ this.enableBitVectors = enableBitVectors;
+ }
+
+ public Boolean getEnableOnlyBitVector() {
+ return enableOnlyBitVector;
+ }
+
+ public void setEnableOnlyBitVector(Boolean enableOnlyBitVector) {
+ this.enableOnlyBitVector = enableOnlyBitVector;
+ }
+
+ public void setDoAlias(boolean doAlias) {
+ this.doAlias = doAlias;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public void setAlias(String alias) {
+ this.alias = alias;
+ }
+
+
+ public void setAliasedName(String aliasedName) {
+ this.aliasedName = aliasedName;
+ }
+
+ public void setTensorType(TensorType tensorType) {
+ this.tensorType = Optional.of(tensorType);
+ }
+
+ public void setDistanceMetric(String value) {
+ this.distanceMetric = Optional.of(value);
+ }
+
+ public void apply(SDField field) {
+ Attribute attribute = null;
+ if (attributeIsSuffixOfStructField(field.getName())) {
+ attribute = field.getAttributes().get(field.getName());
+ }
+ if (attribute == null) {
+ attribute = field.getAttributes().get(name);
+ if (attribute == null) {
+ attribute = new Attribute(name, field.getDataType());
+ field.addAttribute(attribute);
+ }
+ }
+
+ if (huge != null) {
+ attribute.setHuge(huge);
+ }
+ if (paged != null) {
+ attribute.setPaged(paged);
+ }
+ if (fastSearch != null) {
+ attribute.setFastSearch(fastSearch);
+ }
+ if (fastAccess != null) {
+ attribute.setFastAccess(fastAccess);
+ }
+ if (mutable != null) {
+ attribute.setMutable(mutable);
+ }
+ if (enableBitVectors != null) {
+ attribute.setEnableBitVectors(enableBitVectors);
+ }
+ if (enableOnlyBitVector != null) {
+ attribute.setEnableOnlyBitVector(enableOnlyBitVector);
+ }
+ if (doAlias) {
+ field.getAliasToName().put(alias, aliasedName);
+ }
+ if (tensorType.isPresent()) {
+ attribute.setTensorType(tensorType.get());
+ }
+ if (distanceMetric.isPresent()) {
+ String upper = distanceMetric.get().toUpperCase(Locale.ENGLISH);
+ attribute.setDistanceMetric(Attribute.DistanceMetric.valueOf(upper));
+ }
+ }
+
+ private boolean attributeIsSuffixOfStructField(String fieldName) {
+ return ((fieldName.indexOf('.') != -1) && fieldName.endsWith(name));
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/BoldingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/BoldingOperation.java
new file mode 100644
index 00000000000..74e69e047ef
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/BoldingOperation.java
@@ -0,0 +1,25 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+import com.yahoo.vespa.documentmodel.SummaryField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class BoldingOperation implements FieldOperation {
+
+ private final boolean bold;
+
+ public BoldingOperation(boolean bold) {
+ this.bold = bold;
+ }
+
+ public void apply(SDField field) {
+ SummaryField summaryField = field.getSummaryField(field.getName(), true);
+ summaryField.addSource(field.getName());
+ summaryField.addDestination("default");
+ summaryField.setTransform(bold ? summaryField.getTransform().bold() : summaryField.getTransform().unbold());
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/DictionaryOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/DictionaryOperation.java
new file mode 100644
index 00000000000..a9a2ce7cbb1
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/DictionaryOperation.java
@@ -0,0 +1,41 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.Case;
+import com.yahoo.schema.document.Dictionary;
+import com.yahoo.schema.document.SDField;
+
+/**
+ * Represents operations controlling setup of dictionary used for queries
+ *
+ * @author baldersheim
+ */
+public class DictionaryOperation implements FieldOperation {
+ public enum Operation { HASH, BTREE, CASED, UNCASED }
+ private final Operation operation;
+
+ public DictionaryOperation(Operation type) {
+ this.operation = type;
+ }
+ @Override
+ public void apply(SDField field) {
+ Dictionary dictionary = field.getOrSetDictionary();
+ switch (operation) {
+ case HASH:
+ dictionary.updateType(Dictionary.Type.HASH);
+ break;
+ case BTREE:
+ dictionary.updateType(Dictionary.Type.BTREE);
+ break;
+ case CASED:
+ dictionary.updateMatch(Case.CASED);
+ break;
+ case UNCASED:
+ dictionary.updateMatch(Case.UNCASED);
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled operation " + operation);
+ }
+ }
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java
new file mode 100644
index 00000000000..126f594c371
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperation.java
@@ -0,0 +1,22 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+/**
+ * An operation on a field.
+ * Operations has a natural order of execution.
+ *
+ * @author Einar M R Rosenvinge
+ */
+public interface FieldOperation extends Comparable<FieldOperation> {
+
+ /** Apply this operation on the given field */
+ void apply(SDField field);
+
+ @Override
+ default int compareTo(FieldOperation other) {
+ return 0; // no order by default
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperationContainer.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperationContainer.java
new file mode 100644
index 00000000000..d5e52fadffa
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/FieldOperationContainer.java
@@ -0,0 +1,19 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public interface FieldOperationContainer {
+
+ /** Adds an operation */
+ void addOperation(FieldOperation op);
+
+ /** Apply all operations. Operations must be sorted in their natural order before applying each operation. */
+ void applyOperations(SDField field);
+
+ String getName();
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/IdOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IdOperation.java
new file mode 100644
index 00000000000..5e62742085f
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IdOperation.java
@@ -0,0 +1,35 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDDocumentType;
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class IdOperation implements FieldOperation {
+
+ private SDDocumentType document;
+ private int fieldId;
+
+ public SDDocumentType getDocument() {
+ return document;
+ }
+
+ public void setDocument(SDDocumentType document) {
+ this.document = document;
+ }
+
+ public int getFieldId() {
+ return fieldId;
+ }
+
+ public void setFieldId(int fieldId) {
+ this.fieldId = fieldId;
+ }
+
+ public void apply(SDField field) {
+ document.setFieldId(field, fieldId);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexOperation.java
new file mode 100644
index 00000000000..ab5ffa25f33
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexOperation.java
@@ -0,0 +1,134 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.Index;
+import com.yahoo.schema.Index.Type;
+import com.yahoo.schema.document.BooleanIndexDefinition;
+import com.yahoo.schema.document.HnswIndexParams;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.document.Stemming;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.OptionalDouble;
+import java.util.OptionalInt;
+import java.util.OptionalLong;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class IndexOperation implements FieldOperation {
+
+ private String indexName;
+ private Optional<Boolean> prefix = Optional.empty();
+ private List<String> aliases = new LinkedList<>();
+ private Optional<String> stemming = Optional.empty();
+ private Optional<Type> type = Optional.empty();
+
+ private OptionalInt arity = OptionalInt.empty(); // For predicate data type
+ private OptionalLong lowerBound = OptionalLong.empty();
+ private OptionalLong upperBound = OptionalLong.empty();
+ private OptionalDouble densePostingListThreshold = OptionalDouble.empty();
+ private Optional<Boolean> enableBm25 = Optional.empty();
+
+ private Optional<HnswIndexParams.Builder> hnswIndexParams = Optional.empty();
+
+ public String getIndexName() {
+ return indexName;
+ }
+
+ public void setIndexName(String indexName) {
+ this.indexName = indexName;
+ }
+
+ public boolean getPrefix() {
+ return prefix.get();
+ }
+
+ public void setPrefix(Boolean prefix) {
+ this.prefix = Optional.of(prefix);
+ }
+
+ public void addAlias(String alias) {
+ aliases.add(alias);
+ }
+
+ public String getStemming() {
+ return stemming.get();
+ }
+
+ public void setStemming(String stemming) {
+ this.stemming = Optional.of(stemming);
+ }
+
+ public void apply(SDField field) {
+ Index index = field.getIndex(indexName);
+
+ if (index == null) {
+ index = new Index(indexName);
+ field.addIndex(index);
+ }
+
+ applyToIndex(index);
+ }
+
+ public void applyToIndex(Index index) {
+ if (prefix.isPresent()) {
+ index.setPrefix(prefix.get());
+ }
+ for (String alias : aliases) {
+ index.addAlias(alias);
+ }
+ if (stemming.isPresent()) {
+ index.setStemming(Stemming.get(stemming.get()));
+ }
+ if (type.isPresent()) {
+ index.setType(type.get());
+ }
+ if (arity.isPresent() || lowerBound.isPresent() ||
+ upperBound.isPresent() || densePostingListThreshold.isPresent()) {
+ index.setBooleanIndexDefiniton(
+ new BooleanIndexDefinition(arity, lowerBound, upperBound, densePostingListThreshold));
+ }
+ if (enableBm25.isPresent()) {
+ index.setInterleavedFeatures(enableBm25.get());
+ }
+ if (hnswIndexParams.isPresent()) {
+ index.setHnswIndexParams(hnswIndexParams.get().build());
+ }
+ }
+
+ public Type getType() {
+ return type.get();
+ }
+
+ public void setType(Type type) {
+ this.type = Optional.of(type);
+ }
+
+ public void setArity(int arity) {
+ this.arity = OptionalInt.of(arity);
+ }
+
+ public void setLowerBound(long value) {
+ this.lowerBound = OptionalLong.of(value);
+ }
+
+ public void setUpperBound(long value) {
+ this.upperBound = OptionalLong.of(value);
+ }
+
+ public void setDensePostingListThreshold(double densePostingListThreshold) {
+ this.densePostingListThreshold = OptionalDouble.of(densePostingListThreshold);
+ }
+
+ public void setEnableBm25(boolean value) {
+ enableBm25 = Optional.of(value);
+ }
+
+ public void setHnswIndexParams(HnswIndexParams.Builder params) {
+ this.hnswIndexParams = Optional.of(params);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java
new file mode 100644
index 00000000000..bb79a45831e
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/IndexingOperation.java
@@ -0,0 +1,61 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.language.Linguistics;
+import com.yahoo.language.process.Embedder;
+import com.yahoo.language.simple.SimpleLinguistics;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.parser.ParseException;
+import com.yahoo.schema.parser.SimpleCharStream;
+import com.yahoo.vespa.indexinglanguage.ScriptParserContext;
+import com.yahoo.vespa.indexinglanguage.expressions.ScriptExpression;
+import com.yahoo.vespa.indexinglanguage.expressions.StatementExpression;
+import com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig;
+import com.yahoo.yolean.Exceptions;
+
+import java.util.Map;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class IndexingOperation implements FieldOperation {
+
+ private final ScriptExpression script;
+
+ public IndexingOperation(ScriptExpression script) {
+ this.script = script;
+ }
+
+ public ScriptExpression getScript() { return script; }
+
+ public void apply(SDField field) {
+ field.setIndexingScript(script);
+ }
+
+ /** Creates an indexing operation which will use the simple linguistics implementation suitable for testing */
+ public static IndexingOperation fromStream(SimpleCharStream input, boolean multiLine) throws ParseException {
+ return fromStream(input, multiLine, new SimpleLinguistics(), Embedder.throwsOnUse.asMap());
+ }
+
+ public static IndexingOperation fromStream(SimpleCharStream input, boolean multiLine,
+ Linguistics linguistics, Map<String, Embedder> embedders)
+ throws ParseException {
+ ScriptParserContext config = new ScriptParserContext(linguistics, embedders);
+ config.setAnnotatorConfig(new AnnotatorConfig());
+ config.setInputStream(input);
+ ScriptExpression exp;
+ try {
+ if (multiLine) {
+ exp = ScriptExpression.newInstance(config);
+ } else {
+ exp = new ScriptExpression(StatementExpression.newInstance(config));
+ }
+ } catch (com.yahoo.vespa.indexinglanguage.parser.ParseException e) {
+ ParseException t = new ParseException("Could not parse indexing statement: " + Exceptions.toMessageString(e));
+ t.initCause(e);
+ throw t;
+ }
+ return new IndexingOperation(exp);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/MatchOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/MatchOperation.java
new file mode 100644
index 00000000000..a568b5b0f66
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/MatchOperation.java
@@ -0,0 +1,65 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.Case;
+import com.yahoo.schema.document.MatchAlgorithm;
+import com.yahoo.schema.document.MatchType;
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class MatchOperation implements FieldOperation {
+
+ private MatchType matchingType;
+ private Case casing;
+ private Integer gramSize;
+ private Integer maxLength;
+ private MatchAlgorithm matchingAlgorithm;
+ private String exactMatchTerminator;
+
+ public void setMatchingType(MatchType matchingType) {
+ this.matchingType = matchingType;
+ }
+
+ public void setGramSize(Integer gramSize) {
+ this.gramSize = gramSize;
+ }
+ public void setMaxLength(Integer maxLength) {
+ this.maxLength = maxLength;
+ }
+
+ public void setMatchingAlgorithm(MatchAlgorithm matchingAlgorithm) {
+ this.matchingAlgorithm = matchingAlgorithm;
+ }
+
+ public void setExactMatchTerminator(String exactMatchTerminator) {
+ this.exactMatchTerminator = exactMatchTerminator;
+ }
+
+ public void setCase(Case casing) {
+ this.casing = casing;
+ }
+
+ public void apply(SDField field) {
+ if (matchingType != null) {
+ field.setMatchingType(matchingType);
+ }
+ if (casing != null) {
+ field.setMatchingCase(casing);
+ }
+ if (gramSize != null) {
+ field.getMatching().setGramSize(gramSize);
+ }
+ if (maxLength != null) {
+ field.getMatching().maxLength(maxLength);
+ }
+ if (matchingAlgorithm != null) {
+ field.setMatchingAlgorithm(matchingAlgorithm);
+ }
+ if (exactMatchTerminator != null) {
+ field.getMatching().setExactMatchTerminator(exactMatchTerminator);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/NormalizingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/NormalizingOperation.java
new file mode 100644
index 00000000000..561c5b87899
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/NormalizingOperation.java
@@ -0,0 +1,34 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.NormalizeLevel;
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class NormalizingOperation implements FieldOperation {
+
+ private final NormalizeLevel.Level level;
+
+ public NormalizingOperation(String setting) {
+ if ("none".equals(setting)) {
+ this.level = NormalizeLevel.Level.NONE;
+ } else if ("codepoint".equals(setting)) {
+ this.level = NormalizeLevel.Level.CODEPOINT;
+ } else if ("lowercase".equals(setting)) {
+ this.level = NormalizeLevel.Level.LOWERCASE;
+ } else if ("accent".equals(setting)) {
+ this.level = NormalizeLevel.Level.ACCENT;
+ } else if ("all".equals(setting)) {
+ this.level = NormalizeLevel.Level.ACCENT;
+ } else {
+ throw new IllegalArgumentException("invalid normalizing setting: " + setting);
+ }
+ }
+
+ public void apply(SDField field) {
+ field.setNormalizing(new NormalizeLevel(level, true));
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/QueryCommandOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/QueryCommandOperation.java
new file mode 100644
index 00000000000..d0e9feb41e4
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/QueryCommandOperation.java
@@ -0,0 +1,25 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+import java.util.List;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class QueryCommandOperation implements FieldOperation {
+
+ private final List<String> queryCommands = new java.util.ArrayList<>(0);
+
+ public void addQueryCommand(String name) {
+ queryCommands.add(name);
+ }
+
+ public void apply(SDField field) {
+ for (String command : queryCommands) {
+ field.addQueryCommand(command);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankOperation.java
new file mode 100644
index 00000000000..bbc6208ba1b
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankOperation.java
@@ -0,0 +1,36 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class RankOperation implements FieldOperation {
+
+ private Boolean literal = null;
+ private Boolean filter = null;
+ private Boolean normal = null;
+
+ public Boolean getLiteral() { return literal; }
+ public void setLiteral(Boolean literal) { this.literal = literal; }
+
+ public Boolean getFilter() { return filter; }
+ public void setFilter(Boolean filter) { this.filter = filter; }
+
+ public Boolean getNormal() { return normal; }
+ public void setNormal(Boolean n) { this.normal = n; }
+
+ public void apply(SDField field) {
+ if (literal != null) {
+ field.getRanking().setLiteral(literal);
+ }
+ if (filter != null) {
+ field.getRanking().setFilter(filter);
+ }
+ if (normal != null) {
+ field.getRanking().setNormal(normal);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankTypeOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankTypeOperation.java
new file mode 100644
index 00000000000..4a43a907549
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/RankTypeOperation.java
@@ -0,0 +1,43 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.RankType;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.Index;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class RankTypeOperation implements FieldOperation {
+
+ private String indexName;
+ private RankType type;
+
+ public String getIndexName() {
+ return indexName;
+ }
+ public void setIndexName(String indexName) {
+ this.indexName = indexName;
+ }
+
+ public RankType getType() {
+ return type;
+ }
+ public void setType(RankType type) {
+ this.type = type;
+ }
+
+ public void apply(SDField field) {
+ if (indexName == null) {
+ field.setRankType(type); // Set default if the index is not specified.
+ } else {
+ Index index = field.getIndex(indexName);
+ if (index == null) {
+ index = new Index(indexName);
+ field.addIndex(index);
+ }
+ index.setRankType(type);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/SortingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SortingOperation.java
new file mode 100644
index 00000000000..2e981a893ce
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SortingOperation.java
@@ -0,0 +1,93 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.Attribute;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.document.Sorting;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class SortingOperation implements FieldOperation {
+
+ private final String attributeName;
+ private Boolean ascending;
+ private Boolean descending;
+ private Sorting.Function function;
+ private Sorting.Strength strength;
+ private String locale;
+
+ public SortingOperation(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ public Boolean getAscending() {
+ return ascending;
+ }
+
+ public void setAscending() {
+ this.ascending = true;
+ }
+
+ public Boolean getDescending() {
+ return descending;
+ }
+
+ public void setDescending() {
+ this.descending = true;
+ }
+
+ public Sorting.Function getFunction() {
+ return function;
+ }
+
+ public void setFunction(Sorting.Function function) {
+ this.function = function;
+ }
+
+ public Sorting.Strength getStrength() {
+ return strength;
+ }
+
+ public void setStrength(Sorting.Strength strength) {
+ this.strength = strength;
+ }
+
+ public String getLocale() {
+ return locale;
+ }
+
+ public void setLocale(String locale) {
+ this.locale = locale;
+ }
+
+ public void apply(SDField field) {
+ Attribute attribute = field.getAttributes().get(attributeName);
+ if (attribute == null) {
+ attribute = new Attribute(attributeName, field.getDataType());
+ field.addAttribute(attribute);
+ }
+ Sorting sorting = attribute.getSorting();
+
+ if (ascending != null) {
+ sorting.setAscending();
+ }
+ if (descending != null) {
+ sorting.setDescending();
+ }
+ if (function != null) {
+ sorting.setFunction(function);
+ }
+ if (strength != null) {
+ sorting.setStrength(strength);
+ }
+ if (locale != null) {
+ sorting.setLocale(locale);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/StemmingOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/StemmingOperation.java
new file mode 100644
index 00000000000..a4bb00b0d07
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/StemmingOperation.java
@@ -0,0 +1,26 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.document.Stemming;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class StemmingOperation implements FieldOperation {
+
+ private String setting;
+
+ public String getSetting() {
+ return setting;
+ }
+
+ public void setSetting(String setting) {
+ this.setting = setting;
+ }
+
+ public void apply(SDField field) {
+ field.setStemming(Stemming.get(setting));
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/StructFieldOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/StructFieldOperation.java
new file mode 100644
index 00000000000..ac80f5023fc
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/StructFieldOperation.java
@@ -0,0 +1,56 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class StructFieldOperation implements FieldOperation, FieldOperationContainer {
+
+ private final String structFieldName;
+ private final List<FieldOperation> pendingOperations = new LinkedList<>();
+
+ public StructFieldOperation(String structFieldName) {
+ this.structFieldName = structFieldName;
+ }
+
+ public void apply(SDField field) {
+ SDField structField = field.getStructField(structFieldName);
+ if (structField == null ) {
+ throw new IllegalArgumentException("Struct field '" + structFieldName + "' has not been defined in struct " +
+ "for field '" + field.getName() + "'.");
+ }
+
+ applyOperations(structField);
+ }
+
+ @Override
+ public void addOperation(FieldOperation op) {
+ pendingOperations.add(op);
+ }
+
+ @Override
+ public void applyOperations(SDField field) {
+ if (pendingOperations.isEmpty()) return;
+
+ Collections.sort(pendingOperations);
+ ListIterator<FieldOperation> ops = pendingOperations.listIterator();
+ while (ops.hasNext()) {
+ FieldOperation op = ops.next();
+ ops.remove();
+ op.apply(field);
+ }
+ }
+
+ @Override
+ public String getName() {
+ return structFieldName;
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldLongOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldLongOperation.java
new file mode 100644
index 00000000000..4576b7a34fe
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldLongOperation.java
@@ -0,0 +1,70 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.document.DataType;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.vespa.documentmodel.SummaryField;
+
+import java.util.Iterator;
+import java.util.Set;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class SummaryInFieldLongOperation extends SummaryInFieldOperation {
+
+ private DataType type;
+ private Boolean bold;
+ private Set<String> destinations = new java.util.LinkedHashSet<>();
+
+ public SummaryInFieldLongOperation(String name) {
+ super(name);
+ }
+
+ public SummaryInFieldLongOperation() {
+ super(null);
+ }
+
+ public void setType(DataType type) {
+ this.type = type;
+ }
+
+ public void setBold(Boolean bold) {
+ this.bold = bold;
+ }
+
+ public void addDestination(String destination) {
+ destinations.add(destination);
+ }
+
+ public Iterator<String> destinationIterator() {
+ return destinations.iterator();
+ }
+
+ public void apply(SDField field) {
+ if (type == null) {
+ type = field.getDataType();
+ }
+ SummaryField summary = new SummaryField(name, type);
+ applyToSummary(summary);
+ field.addSummaryField(summary);
+ }
+
+ public void applyToSummary(SummaryField summary) {
+ if (transform != null) {
+ summary.setTransform(transform);
+ }
+
+ if (bold != null) {
+ summary.setTransform(bold ? summary.getTransform().bold() : summary.getTransform().unbold());
+ }
+
+ for (SummaryField.Source source : sources) {
+ summary.addSource(source);
+ }
+
+ for (String destination : destinations) {
+ summary.addDestination(destination);
+ }
+ }
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldOperation.java
new file mode 100644
index 00000000000..dd06d920aac
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldOperation.java
@@ -0,0 +1,46 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.vespa.documentmodel.SummaryField;
+import com.yahoo.vespa.documentmodel.SummaryTransform;
+
+import java.util.Set;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public abstract class SummaryInFieldOperation implements FieldOperation {
+
+ protected String name;
+ protected SummaryTransform transform;
+ protected Set<SummaryField.Source> sources = new java.util.LinkedHashSet<>();
+
+ public SummaryInFieldOperation(String name) {
+ this.name = name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setTransform(SummaryTransform transform) {
+ this.transform = transform;
+ }
+
+ public SummaryTransform getTransform() {
+ return transform;
+ }
+
+ public void addSource(String name) {
+ sources.add(new SummaryField.Source(name));
+ }
+
+ public void addSource(SummaryField.Source source) {
+ sources.add(source);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldShortOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldShortOperation.java
new file mode 100644
index 00000000000..ccc22719f25
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryInFieldShortOperation.java
@@ -0,0 +1,32 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+import com.yahoo.vespa.documentmodel.SummaryField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class SummaryInFieldShortOperation extends SummaryInFieldOperation {
+
+ public SummaryInFieldShortOperation(String name) {
+ super(name);
+ }
+
+ public void apply(SDField field) {
+ SummaryField ret = field.getSummaryField(name);
+ if (ret == null) {
+ ret = new SummaryField(name, field.getDataType());
+ ret.addSource(field.getName());
+ ret.addDestination("default");
+ }
+ ret.setImplicit(false);
+
+ ret.setTransform(transform);
+ for (SummaryField.Source source : sources) {
+ ret.addSource(source);
+ }
+ field.addSummaryField(ret);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryToOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryToOperation.java
new file mode 100644
index 00000000000..2d9cf3acf4e
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/SummaryToOperation.java
@@ -0,0 +1,41 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+import com.yahoo.vespa.documentmodel.SummaryField;
+
+import java.util.Set;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class SummaryToOperation implements FieldOperation {
+
+ private Set<String> destinations = new java.util.LinkedHashSet<>();
+ private String name;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void addDestination(String destination) {
+ destinations.add(destination);
+ }
+
+ public void apply(SDField field) {
+ SummaryField summary;
+ summary = field.getSummaryField(name);
+ if (summary == null) {
+ summary = new SummaryField(field);
+ summary.addSource(field.getName());
+ summary.addDestination("default");
+ field.addSummaryField(summary);
+ }
+ summary.setImplicit(false);
+
+ for (String destination : destinations) {
+ summary.addDestination(destination);
+ }
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightOperation.java
new file mode 100644
index 00000000000..57c28d9bdb5
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightOperation.java
@@ -0,0 +1,25 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.SDField;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class WeightOperation implements FieldOperation {
+
+ private int weight;
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public void apply(SDField field) {
+ field.setWeight(weight);
+ }
+
+}
diff --git a/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightedSetOperation.java b/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightedSetOperation.java
new file mode 100644
index 00000000000..8fb0cc9fcdb
--- /dev/null
+++ b/config-model/src/main/java/com/yahoo/schema/fieldoperation/WeightedSetOperation.java
@@ -0,0 +1,70 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.fieldoperation;
+
+import com.yahoo.schema.document.Attribute;
+import com.yahoo.document.DataType;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.document.WeightedSetDataType;
+
+/**
+ * @author Einar M R Rosenvinge
+ */
+public class WeightedSetOperation implements FieldOperation {
+
+ private Boolean createIfNonExistent;
+ private Boolean removeIfZero;
+
+ public Boolean getCreateIfNonExistent() {
+ return createIfNonExistent;
+ }
+
+ public void setCreateIfNonExistent(Boolean createIfNonExistent) {
+ this.createIfNonExistent = createIfNonExistent;
+ }
+
+ public Boolean getRemoveIfZero() {
+ return removeIfZero;
+ }
+
+ public void setRemoveIfZero(Boolean removeIfZero) {
+ this.removeIfZero = removeIfZero;
+ }
+
+ public void apply(SDField field) {
+ WeightedSetDataType ctype = (WeightedSetDataType) field.getDataType();
+
+ if (createIfNonExistent != null) {
+ field.setDataType(DataType.getWeightedSet(ctype.getNestedType(), createIfNonExistent,
+ ctype.removeIfZero()));
+ }
+
+ ctype = (WeightedSetDataType) field.getDataType();
+ if (removeIfZero != null) {
+ field.setDataType(DataType.getWeightedSet(ctype.getNestedType(),
+ ctype.createIfNonExistent(), removeIfZero));
+ }
+
+ ctype = (WeightedSetDataType) field.getDataType();
+ for (Object o : field.getAttributes().values()) {
+ Attribute attribute = (Attribute) o;
+ attribute.setRemoveIfZero(ctype.removeIfZero());
+ attribute.setCreateIfNonExistent(ctype.createIfNonExistent());
+ }
+ }
+
+ @Override
+ public int compareTo(FieldOperation other) {
+ // this operation should be executed first because it modifies the type of weighted sets, and other
+ // operation depends on the type of the weighted set
+ return -1;
+ }
+
+ @Override
+ public String toString() {
+ return "WeightedSetOperation{" +
+ "createIfNonExistent=" + createIfNonExistent +
+ ", removeIfZero=" + removeIfZero +
+ '}';
+ }
+
+}