diff options
author | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
---|---|---|
committer | Jon Bratseth <bratseth@yahoo-inc.com> | 2016-06-15 23:09:44 +0200 |
commit | 72231250ed81e10d66bfe70701e64fa5fe50f712 (patch) | |
tree | 2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation |
Publish
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation')
25 files changed, 1110 insertions, 0 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AliasOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AliasOperation.java new file mode 100644 index 00000000000..60aeb3d50cc --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AliasOperation.java @@ -0,0 +1,40 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/AttributeOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java new file mode 100644 index 00000000000..19ee857c627 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/AttributeOperation.java @@ -0,0 +1,153 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.Attribute; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.tensor.TensorType; + +import java.util.Optional; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class AttributeOperation implements FieldOperation, FieldOperationContainer { + private final String name; + private Boolean huge; + private Boolean fastSearch; + private Boolean fastAccess; + private Boolean prefetch; + private Boolean enableBitVectors; + private Boolean enableOnlyBitVector; + //TODO: Husk sorting!! + private boolean doAlias = false; + private String alias; + private String aliasedName; + private Optional<TensorType> tensorType = Optional.empty(); + + public AttributeOperation(String name) { + this.name = name; + } + + public void addOperation(FieldOperation op) { + //TODO: Implement this method: + + } + + public void applyOperations(SDField field) { + //TODO: Implement this method: + + } + + 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 Boolean getPrefetch() { + return prefetch; + } + + public void setPrefetch(Boolean prefetch) { + this.prefetch = prefetch; + } + + 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 boolean isDoAlias() { + return doAlias; + } + + public void setDoAlias(boolean doAlias) { + this.doAlias = doAlias; + } + + public String getAlias() { + return alias; + } + + public void setAlias(String alias) { + this.alias = alias; + } + + public String getAliasedName() { + return aliasedName; + } + + public void setAliasedName(String aliasedName) { + this.aliasedName = aliasedName; + } + + public void setTensorType(TensorType tensorType) { + this.tensorType = Optional.of(tensorType); + } + + public void apply(SDField field) { + Attribute attribute = field.getAttributes().get(name); + if (attribute == null) { + attribute = new Attribute(name, field.getDataType()); + field.addAttribute(attribute); + } + + if (huge != null) { + attribute.setHuge(huge); + } + if (fastSearch != null) { + attribute.setFastSearch(fastSearch); + } + if (fastAccess != null) { + attribute.setFastAccess(fastAccess); + } + if (prefetch != null) { + attribute.setPrefetch(prefetch); + } + 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()); + } + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BodyOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BodyOperation.java new file mode 100644 index 00000000000..b830407ea2e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BodyOperation.java @@ -0,0 +1,14 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class BodyOperation implements FieldOperation { + public void apply(SDField field) { + field.setHeader(false); + field.setHeaderOrBodyDefined(true); + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BoldingOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BoldingOperation.java new file mode 100644 index 00000000000..f6c7277869e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/BoldingOperation.java @@ -0,0 +1,24 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.vespa.documentmodel.SummaryField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/FieldOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/FieldOperation.java new file mode 100644 index 00000000000..20caf0b13c7 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/FieldOperation.java @@ -0,0 +1,11 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public interface FieldOperation { + public void apply(SDField field); +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/FieldOperationContainer.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/FieldOperationContainer.java new file mode 100644 index 00000000000..30d16e369b1 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/FieldOperationContainer.java @@ -0,0 +1,13 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public interface FieldOperationContainer { + public void addOperation(FieldOperation op); + public void applyOperations(SDField field); + public String getName(); +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/HeaderOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/HeaderOperation.java new file mode 100644 index 00000000000..48d2711b39e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/HeaderOperation.java @@ -0,0 +1,14 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class HeaderOperation implements FieldOperation { + public void apply(SDField field) { + field.setHeader(true); + field.setHeaderOrBodyDefined(true); + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IdOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IdOperation.java new file mode 100644 index 00000000000..25318e2db85 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IdOperation.java @@ -0,0 +1,33 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDDocumentType; +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/IndexOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java new file mode 100644 index 00000000000..8ab065ce419 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java @@ -0,0 +1,114 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.Index; +import com.yahoo.searchdefinition.Index.Type; +import com.yahoo.searchdefinition.document.BooleanIndexDefinition; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.searchdefinition.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 <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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 in boolean search + private OptionalLong lowerBound = OptionalLong.empty(); + private OptionalLong upperBound = OptionalLong.empty(); + private OptionalDouble densePostingListThreshold = OptionalDouble.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)); + } + } + + 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); + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingOperation.java new file mode 100644 index 00000000000..af3852bffb8 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingOperation.java @@ -0,0 +1,53 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.language.Linguistics; +import com.yahoo.language.simple.SimpleLinguistics; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.searchdefinition.parser.ParseException; +import com.yahoo.searchdefinition.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; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class IndexingOperation implements FieldOperation { + + private final ScriptExpression script; + + public IndexingOperation(ScriptExpression script) { + this.script = 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()); + } + + public static IndexingOperation fromStream(SimpleCharStream input, boolean multiLine, Linguistics linguistics) + throws ParseException { + ScriptParserContext config = new ScriptParserContext(linguistics); + 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("Error reported by IL parser: " + e.getMessage()); + t.initCause(e); + throw t; + } + return new IndexingOperation(exp); + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingRewriteOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingRewriteOperation.java new file mode 100644 index 00000000000..a416895a6a7 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexingRewriteOperation.java @@ -0,0 +1,12 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class IndexingRewriteOperation implements FieldOperation { + public void apply(SDField field) { + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/MatchOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/MatchOperation.java new file mode 100644 index 00000000000..9128778b7ea --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/MatchOperation.java @@ -0,0 +1,53 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.Matching; +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class MatchOperation implements FieldOperation { + private Matching.Type matchingType; + private Integer gramSize; + private Integer maxLength; + private Matching.Algorithm matchingAlgorithm; + private String exactMatchTerminator; + + public void setMatchingType(Matching.Type matchingType) { + this.matchingType = matchingType; + } + + public void setGramSize(Integer gramSize) { + this.gramSize = gramSize; + } + public void setMaxLength(Integer maxLength) { + this.maxLength = maxLength; + } + + public void setMatchingAlgorithm(Matching.Algorithm matchingAlgorithm) { + this.matchingAlgorithm = matchingAlgorithm; + } + + public void setExactMatchTerminator(String exactMatchTerminator) { + this.exactMatchTerminator = exactMatchTerminator; + } + + public void apply(SDField field) { + if (matchingType != null) { + field.setMatchingType(matchingType); + } + 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/searchdefinition/fieldoperation/NormalizingOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/NormalizingOperation.java new file mode 100644 index 00000000000..e0d15cabbe0 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/NormalizingOperation.java @@ -0,0 +1,32 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.NormalizeLevel; +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class NormalizingOperation implements FieldOperation { + private 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/searchdefinition/fieldoperation/QueryCommandOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/QueryCommandOperation.java new file mode 100644 index 00000000000..e4af5660e7b --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/QueryCommandOperation.java @@ -0,0 +1,23 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +import java.util.List; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class QueryCommandOperation implements FieldOperation { + private 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/searchdefinition/fieldoperation/RankOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/RankOperation.java new file mode 100644 index 00000000000..42b1e5514a1 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/RankOperation.java @@ -0,0 +1,35 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/RankTypeOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/RankTypeOperation.java new file mode 100644 index 00000000000..640ccc48818 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/RankTypeOperation.java @@ -0,0 +1,41 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.RankType; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.searchdefinition.Index; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/SortingOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SortingOperation.java new file mode 100644 index 00000000000..e9225f0def5 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SortingOperation.java @@ -0,0 +1,91 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.Attribute; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.searchdefinition.document.Sorting; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class SortingOperation implements FieldOperation { + private 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/searchdefinition/fieldoperation/StemmingOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/StemmingOperation.java new file mode 100644 index 00000000000..19b760386a1 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/StemmingOperation.java @@ -0,0 +1,24 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.searchdefinition.document.Stemming; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/StructFieldOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/StructFieldOperation.java new file mode 100644 index 00000000000..f0c3d964934 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/StructFieldOperation.java @@ -0,0 +1,50 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class StructFieldOperation implements FieldOperation, FieldOperationContainer { + private String structFieldName; + private 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); + } + + public void addOperation(FieldOperation op) { + pendingOperations.add(op); + } + + public void applyOperations(SDField field) { + if (pendingOperations.isEmpty()) { + return; + } + ListIterator<FieldOperation> ops = pendingOperations.listIterator(); + while (ops.hasNext()) { + FieldOperation op = ops.next(); + ops.remove(); + op.apply(field); + } + } + + public String getName() { + return structFieldName; + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldLongOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldLongOperation.java new file mode 100644 index 00000000000..f320ef649b4 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldLongOperation.java @@ -0,0 +1,81 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.document.DataType; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.vespa.documentmodel.SummaryField; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +public class SummaryInFieldLongOperation extends SummaryInFieldOperation { + private DataType type; + private Boolean bold; + private Set<String> destinations = new java.util.LinkedHashSet<>(); + private List<SummaryField.Property> properties = new ArrayList<>(); + + 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 addProperty(SummaryField.Property property) { + properties.add(property); + } + + 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); + } + + for (SummaryField.Property prop : properties) { + summary.addProperty(prop.getName(), prop.getValue()); + } + } +} diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldOperation.java new file mode 100644 index 00000000000..e1abbcc93b5 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldOperation.java @@ -0,0 +1,44 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.vespa.documentmodel.SummaryField; +import com.yahoo.vespa.documentmodel.SummaryTransform; + +import java.util.Set; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/SummaryInFieldShortOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldShortOperation.java new file mode 100644 index 00000000000..1ffb8d9a83e --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryInFieldShortOperation.java @@ -0,0 +1,30 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.vespa.documentmodel.SummaryField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/SummaryToOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryToOperation.java new file mode 100644 index 00000000000..f392b2fdcc8 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/SummaryToOperation.java @@ -0,0 +1,39 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.vespa.documentmodel.SummaryField; + +import java.util.Set; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/WeightOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/WeightOperation.java new file mode 100644 index 00000000000..3cbd557b850 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/WeightOperation.java @@ -0,0 +1,23 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.SDField; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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/searchdefinition/fieldoperation/WeightedSetOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/WeightedSetOperation.java new file mode 100644 index 00000000000..c1721a4dbb5 --- /dev/null +++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/WeightedSetOperation.java @@ -0,0 +1,63 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.searchdefinition.fieldoperation; + +import com.yahoo.searchdefinition.document.Attribute; +import com.yahoo.document.DataType; +import com.yahoo.searchdefinition.document.SDField; +import com.yahoo.document.WeightedSetDataType; + +/** + * @author <a href="mailto:einarmr@yahoo-inc.com">Einar M R Rosenvinge</a> + */ +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 String toString() { + return "WeightedSetOperation{" + + "createIfNonExistent=" + createIfNonExistent + + ", removeIfZero=" + removeIfZero + + '}'; + } + +} |