diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-21 22:04:08 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-04-21 22:04:08 +0200 |
commit | fd312e371f36079c90ce9e570485aa8c2bcab196 (patch) | |
tree | 8b711ca3b6821295b09be4959e4e2a92593c425e /config-model | |
parent | daa7010d1d953e7c18f74e9e46755d9a250a353a (diff) |
Propagate query cased/uncased control-to-attributes.
Diffstat (limited to 'config-model')
4 files changed, 47 insertions, 7 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 65df7f395ae..125b0cf2763 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 @@ -258,6 +258,7 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce aaB.dictionary.type(convert(dictionary.getType())); aaB.dictionary.match(convert(dictionary.getMatch())); } + aaB.match(convertMatch(attribute.getCase())); return aaB; } @@ -281,6 +282,15 @@ public class AttributeFields extends Derived implements AttributesConfig.Produce } return AttributesConfig.Attribute.Dictionary.Match.UNCASED; } + private static AttributesConfig.Attribute.Match.Enum convertMatch(Case type) { + switch (type) { + case CASED: + return AttributesConfig.Attribute.Match.CASED; + case UNCASED: + return AttributesConfig.Attribute.Match.UNCASED; + } + return AttributesConfig.Attribute.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 8841eee79cc..0cf7a031dbc 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 @@ -79,6 +79,7 @@ public final class Attribute implements Cloneable, Serializable { private final Set<String> aliases = new LinkedHashSet<>(); private Dictionary dictionary = null; + private Case casing = Case.UNCASED; /** * True if this attribute should be returned during first pass of search. @@ -104,7 +105,7 @@ public final class Attribute implements Cloneable, Serializable { private final String myName; // different from what name() returns. private final String exportAttributeTypeName; - private Type(String name, String exportAttributeTypeName) { + Type(String name, String exportAttributeTypeName) { this.myName=name; this.exportAttributeTypeName = exportAttributeTypeName; } @@ -126,7 +127,7 @@ public final class Attribute implements Cloneable, Serializable { private final String name; - private CollectionType(String name) { + CollectionType(String name) { this.name=name; } @@ -211,6 +212,7 @@ public final class Attribute implements Cloneable, Serializable { public Sorting getSorting() { return sorting; } public Dictionary getDictionary() { return dictionary; } + public Case getCase() { return casing; } public void setRemoveIfZero(boolean remove) { this.removeIfZero = remove; } public void setCreateIfNonExistent(boolean create) { this.createIfNonExistent = create; } @@ -235,6 +237,7 @@ public final class Attribute implements Cloneable, Serializable { public void setDistanceMetric(DistanceMetric metric) { this.distanceMetric = Optional.of(metric); } public void setHnswIndexParams(HnswIndexParams params) { this.hnswIndexParams = Optional.of(params); } public void setDictionary(Dictionary dictionary) { this.dictionary = dictionary; } + public void setCase(Case casing) { this.casing = casing; } public String getName() { return name; } public Type getType() { return type; } 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 7b1dfde5cb3..ba3baa3147a 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 @@ -26,10 +26,11 @@ public class DictionaryProcessor extends Processor { @Override public void process(boolean validate, boolean documentsOnly) { for (SDField field : search.allConcreteFields()) { - Dictionary dictionary = field.getDictionary(); - if (dictionary == null) continue; Attribute attribute = field.getAttribute(); if (attribute == null) continue; + attribute.setCase(field.getMatching().getCase()); + Dictionary dictionary = field.getDictionary(); + if (dictionary == null) continue; if (attribute.getDataType().getPrimitiveType() instanceof NumericDataType ) { if (attribute.isFastSearch()) { attribute.setDictionary(dictionary); @@ -38,7 +39,6 @@ public class DictionaryProcessor extends Processor { } } else if (attribute.getDataType().getPrimitiveType() == PrimitiveDataType.STRING) { attribute.setDictionary(dictionary); - Matching matching = field.getMatching(); if (dictionary.getType() == Dictionary.Type.HASH) { if (dictionary.getMatch() != Case.CASED) { fail(search, field, "hash dictionary require cased match"); @@ -48,8 +48,8 @@ public class DictionaryProcessor extends Processor { fail(search, field, "btree dictionary require uncased match"); } } - if (! dictionary.getMatch().equals(matching.getCase())) { - fail(search, field, "Dictionary casing '" + dictionary.getMatch() + "' does not match field match casing '" + matching.getCase() + "'"); + if (! dictionary.getMatch().equals(attribute.getCase())) { + fail(search, field, "Dictionary casing '" + dictionary.getMatch() + "' does not match field match casing '" + attribute.getCase() + "'"); } } else { fail(search, field, "You can only specify 'dictionary:' for numeric or string fields"); diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java index f07f214c9db..47122ccac88 100644 --- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java +++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/DictionaryTestCase.java @@ -225,4 +225,31 @@ public class DictionaryTestCase { assertEquals("For search 'test', field 'n1': You must specify 'attribute:fast-search' to allow dictionary control", e.getMessage()); } } + + @Test + public void testCasingForNonFastSearch() throws ParseException { + String def = TestUtil.joinLines( + "search test {", + " document test {", + " field s1 type string {", + " indexing: attribute | summary", + " }", + " field s2 type string {", + " indexing: attribute | summary", + " match:uncased", + " }", + " field s3 type string {", + " indexing: attribute | summary", + " match:cased", + " }", + " }", + "}"); + Search search = createSearch(def); + assertEquals(Case.UNCASED, search.getAttribute("s1").getCase()); + assertEquals(Case.UNCASED, search.getAttribute("s2").getCase()); + assertEquals(Case.CASED, search.getAttribute("s3").getCase()); + assertEquals(AttributesConfig.Attribute.Match.UNCASED, getConfig(search).attribute().get(0).match()); + assertEquals(AttributesConfig.Attribute.Match.UNCASED, getConfig(search).attribute().get(1).match()); + assertEquals(AttributesConfig.Attribute.Match.CASED, getConfig(search).attribute().get(2).match()); + } } |