summaryrefslogtreecommitdiffstats
path: root/config-model/src/main/java/com/yahoo/searchdefinition
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-04-12 09:25:41 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2021-04-12 09:25:46 +0200
commit787fa05cebd66820136372164b7e1b2805f9f061 (patch)
tree264c403f21b98bc5d4d1d65f0b49f378b4184b3b /config-model/src/main/java/com/yahoo/searchdefinition
parent015ade7cd232f217dd964da037ab202731b37cef (diff)
Control cased/uncased in dictionary setting
Diffstat (limited to 'config-model/src/main/java/com/yahoo/searchdefinition')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java10
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java2
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/Dictionary.java28
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java9
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/DictionaryOperation.java35
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/DictionaryProcessor.java7
6 files changed, 66 insertions, 25 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java b/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java
index 4a415fccbcc..4277f503440 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/derived/AttributeFields.java
@@ -255,6 +255,7 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce
Dictionary dictionary = attribute.getDictionary();
if (dictionary != null) {
aaB.dictionary.type(convert(dictionary.getType()));
+ aaB.dictionary.match(convert(dictionary.getMatch()));
}
return aaB;
}
@@ -270,6 +271,15 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce
}
return AttributesConfig.Attribute.Dictionary.Type.BTREE;
}
+ private static AttributesConfig.Attribute.Dictionary.Match.Enum convert(Dictionary.Match type) {
+ switch (type) {
+ case CASED:
+ return AttributesConfig.Attribute.Dictionary.Match.CASED;
+ case UNCASED:
+ return AttributesConfig.Attribute.Dictionary.Match.UNCASED;
+ }
+ return AttributesConfig.Attribute.Dictionary.Match.UNCASED;
+ }
public void getConfig(AttributesConfig.Builder builder, FieldSet fs) {
for (Attribute attribute : attributes.values()) {
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
index f230a7c10eb..8841eee79cc 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Attribute.java
@@ -78,7 +78,7 @@ public final class Attribute implements Cloneable, Serializable {
/** The aliases for this attribute */
private final Set<String> aliases = new LinkedHashSet<>();
- private Dictionary dictionary = new Dictionary();
+ private Dictionary dictionary = null;
/**
* True if this attribute should be returned during first pass of search.
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/Dictionary.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/Dictionary.java
index e492d572f27..8f22b344e44 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/Dictionary.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/Dictionary.java
@@ -9,8 +9,28 @@ package com.yahoo.searchdefinition.document;
*/
public class Dictionary {
public enum Type { BTREE, HASH, BTREE_AND_HASH };
- private final Type type;
- public Dictionary() { this(Type.BTREE); }
- public Dictionary(Type type) { this.type = type; }
- public Type getType() { return type; }
+ public enum Match { CASED, UNCASED };
+ private Type type = null;
+ private Match match = null;
+
+ public void updateType(Type type) {
+ if (this.type == null) {
+ this.type = type;
+ } else if ((this.type == Type.BTREE) && (type == Type.HASH)) {
+ this.type = Type.BTREE_AND_HASH;
+ } else if ((this.type == Type.HASH) && (type == Type.BTREE)) {
+ this.type = Type.BTREE_AND_HASH;
+ } else {
+ throw new IllegalArgumentException("Can not combine previous dictionary setting " + this.type +
+ " with current " + type);
+ }
+ }
+ public void updateMatch(Match match) {
+ if (this.match != null) {
+ throw new IllegalArgumentException("dictionary match mode has already been set to " + this.match);
+ }
+ this.match = match;
+ }
+ public Type getType() { return (type != null) ? type : Type.BTREE; }
+ public Match getMatch() { return (match != null) ? match : Match.UNCASED; }
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
index 76b707fa19b..ebfdf6b1f6e 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/document/SDField.java
@@ -538,9 +538,12 @@ public class SDField extends Field implements TypedKey, FieldOperationContainer,
* Returns Dictionary settings.
*/
public Dictionary getDictionary() { return dictionary; }
-
-
- public void setDictionary(Dictionary dictionary) { this.dictionary=dictionary; }
+ public Dictionary getOrSetDictionary() {
+ if (dictionary == null) {
+ dictionary = new Dictionary();
+ }
+ return dictionary;
+ }
/**
* Set the matching type for this field and all subfields.
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/DictionaryOperation.java b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/DictionaryOperation.java
index ce7c5a71a21..70b0706df29 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/DictionaryOperation.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/fieldoperation/DictionaryOperation.java
@@ -11,25 +11,30 @@ import com.yahoo.searchdefinition.document.SDField;
* @author baldersheim
*/
public class DictionaryOperation implements FieldOperation {
- private final Dictionary.Type type;
+ public enum Operation { HASH, BTREE, CASED, UNCASED }
+ private final Operation operation;
- public DictionaryOperation(Dictionary.Type type) {
- this.type = type;
+ public DictionaryOperation(Operation type) {
+ this.operation = type;
}
@Override
public void apply(SDField field) {
- Dictionary prev = field.getDictionary();
- if (prev == null) {
- field.setDictionary(new Dictionary(type));
- } else if ((prev.getType() == Dictionary.Type.BTREE && type == Dictionary.Type.HASH) ||
- (prev.getType() == Dictionary.Type.HASH && type == Dictionary.Type.BTREE))
- {
- field.setDictionary(new Dictionary(Dictionary.Type.BTREE_AND_HASH));
- } else {
- if (prev.getType() != type) {
- throw new IllegalArgumentException("Can not combine previous dictionary setting " + prev.getType() +
- " with current " + type);
- }
+ 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(Dictionary.Match.CASED);
+ break;
+ case UNCASED:
+ dictionary.updateMatch(Dictionary.Match.UNCASED);
+ break;
+ default:
+ throw new IllegalArgumentException("Unhandled operation " + operation);
}
}
}
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/DictionaryProcessor.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/DictionaryProcessor.java
index fd567ec2d54..66df78466e6 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/DictionaryProcessor.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/DictionaryProcessor.java
@@ -3,6 +3,7 @@ package com.yahoo.searchdefinition.processing;
import com.yahoo.config.application.api.DeployLogger;
import com.yahoo.document.NumericDataType;
+import com.yahoo.document.PrimitiveDataType;
import com.yahoo.searchdefinition.RankProfileRegistry;
import com.yahoo.searchdefinition.Search;
import com.yahoo.searchdefinition.document.Attribute;
@@ -25,16 +26,18 @@ public class DictionaryProcessor extends Processor {
for (SDField field : search.allConcreteFields()) {
Dictionary dictionary = field.getDictionary();
if (dictionary == null) continue;
-
Attribute attribute = field.getAttribute();
+ if (attribute == null) continue;
if (attribute.getDataType().getPrimitiveType() instanceof NumericDataType ) {
if (attribute.isFastSearch()) {
attribute.setDictionary(dictionary);
} else {
fail(search, field, "You must specify 'attribute:fast-search' to allow dictionary control");
}
+ } else if (attribute.getDataType().getPrimitiveType() == PrimitiveDataType.STRING) {
+ attribute.setDictionary(dictionary);
} else {
- fail(search, field, "You can only specify 'dictionary:' for numeric fields");
+ fail(search, field, "You can only specify 'dictionary:' for numeric or string fields");
}
}
}