summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java
Publish
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/IndexOperation.java114
1 files changed, 114 insertions, 0 deletions
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);
+ }
+}