summaryrefslogtreecommitdiffstats
path: root/config-model
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@verizonmedia.com>2019-08-05 16:49:35 +0200
committerJon Bratseth <bratseth@verizonmedia.com>2019-08-05 16:49:35 +0200
commitc9948e8a8ce64f5ae819adc9e9ff2834700c582e (patch)
tree2a700dd9512193d5543feee4ba05d9fb3cb433f9 /config-model
parent00eda613b439d53facdcc3d261b828454446faa0 (diff)
Allow both attribute and index with n-gram
Diffstat (limited to 'config-model')
-rw-r--r--config-model/src/main/java/com/yahoo/searchdefinition/processing/NGramMatch.java9
-rw-r--r--config-model/src/test/examples/ngram.sd4
-rw-r--r--config-model/src/test/java/com/yahoo/searchdefinition/processing/NGramTestCase.java4
3 files changed, 7 insertions, 10 deletions
diff --git a/config-model/src/main/java/com/yahoo/searchdefinition/processing/NGramMatch.java b/config-model/src/main/java/com/yahoo/searchdefinition/processing/NGramMatch.java
index 3f3fc11380b..35c123de78f 100644
--- a/config-model/src/main/java/com/yahoo/searchdefinition/processing/NGramMatch.java
+++ b/config-model/src/main/java/com/yahoo/searchdefinition/processing/NGramMatch.java
@@ -36,12 +36,12 @@ public class NGramMatch extends Processor {
}
private void implementGramMatch(Search search, SDField field, boolean validate) {
- if (validate && field.doesAttributing())
- throw new IllegalArgumentException("gram matching is not supported with attributes, use 'index' not 'attribute' in indexing");
+ if (validate && field.doesAttributing() && ! field.doesIndexing())
+ throw new IllegalArgumentException("gram matching is not supported with attributes, use 'index' in indexing");
int n = field.getMatching().getGramSize();
if (n < 0)
- n=DEFAULT_GRAM_SIZE; // not set - use default gram size
+ n = DEFAULT_GRAM_SIZE; // not set - use default gram size
if (validate && n == 0)
throw new IllegalArgumentException("Illegal gram size in " + field + ": Must be at least 1");
field.getNormalizing().inferCodepoint();
@@ -67,9 +67,8 @@ public class NGramMatch extends Processor {
@Override
protected Expression newTransform(DataType fieldType) {
Expression exp = new NGramExpression(null, ngram);
- if (fieldType instanceof CollectionDataType) {
+ if (fieldType instanceof CollectionDataType)
exp = new ForEachExpression(exp);
- }
return exp;
}
diff --git a/config-model/src/test/examples/ngram.sd b/config-model/src/test/examples/ngram.sd
index 6324dd0fbd1..5d70d8dc536 100644
--- a/config-model/src/test/examples/ngram.sd
+++ b/config-model/src/test/examples/ngram.sd
@@ -13,9 +13,8 @@ search ngram {
}
field gram_2 type string {
- indexing: index
+ indexing: attribute | index # index take precedence for matching
match: gram # gram-size 2 is default
- # index-to: gram_2, default
}
field gram_3 type string {
@@ -24,7 +23,6 @@ search ngram {
gram
gram-size: 3
}
- # index-to: gram_3, default
}
}
diff --git a/config-model/src/test/java/com/yahoo/searchdefinition/processing/NGramTestCase.java b/config-model/src/test/java/com/yahoo/searchdefinition/processing/NGramTestCase.java
index 0219d86e182..9c259cd484e 100644
--- a/config-model/src/test/java/com/yahoo/searchdefinition/processing/NGramTestCase.java
+++ b/config-model/src/test/java/com/yahoo/searchdefinition/processing/NGramTestCase.java
@@ -37,7 +37,7 @@ public class NGramTestCase extends SearchDefinitionTestCase {
assertEquals(3,gram3.getMatching().getGramSize());
assertEquals("input gram_1 | ngram 1 | index gram_1 | summary gram_1",gram1.getIndexingScript().iterator().next().toString());
- assertEquals("input gram_2 | ngram 2 | index gram_2",gram2.getIndexingScript().iterator().next().toString());
+ assertEquals("input gram_2 | ngram 2 | attribute gram_2 | index gram_2",gram2.getIndexingScript().iterator().next().toString());
assertEquals("input gram_3 | ngram 3 | index gram_3",gram3.getIndexingScript().iterator().next().toString());
assertFalse(gram1.getNormalizing().doRemoveAccents());
@@ -77,7 +77,7 @@ public class NGramTestCase extends SearchDefinitionTestCase {
fail("Should cause an exception");
}
catch (IllegalArgumentException e) {
- assertEquals("gram matching is not supported with attributes, use 'index' not 'attribute' in indexing",e.getMessage());
+ assertEquals("gram matching is not supported with attributes, use 'index' in indexing",e.getMessage());
}
}