aboutsummaryrefslogtreecommitdiffstats
path: root/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
committerJon Bratseth <bratseth@gmail.com>2022-05-19 12:03:06 +0200
commit5c24dc5c9642a8d9ed70aee4c950fd0678a1ebec (patch)
treebd9b74bf00c832456f0b83c1b2cd7010be387d68 /config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java
parentf17c4fe7de4c55f5c4ee61897eab8c2f588d8405 (diff)
Rename the 'searchdefinition' package to 'schema'
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java')
-rw-r--r--config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java b/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java
new file mode 100644
index 00000000000..912e6fcf030
--- /dev/null
+++ b/config-model/src/test/java/com/yahoo/schema/processing/NGramTestCase.java
@@ -0,0 +1,88 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.schema.processing;
+
+import com.yahoo.schema.Schema;
+import com.yahoo.schema.ApplicationBuilder;
+import com.yahoo.schema.AbstractSchemaTestCase;
+import com.yahoo.schema.document.MatchType;
+import com.yahoo.schema.document.SDField;
+import com.yahoo.schema.document.Stemming;
+import com.yahoo.schema.parser.ParseException;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+/**
+ * @author bratseth
+ */
+public class NGramTestCase extends AbstractSchemaTestCase {
+
+ @Test
+ public void testNGram() throws IOException, ParseException {
+ Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/ngram.sd");
+ assertNotNull(schema);
+
+ SDField gram1 = schema.getConcreteField("gram_1");
+ assertEquals(MatchType.GRAM, gram1.getMatching().getType());
+ assertEquals(1, gram1.getMatching().getGramSize());
+
+ SDField gram2 = schema.getConcreteField("gram_2");
+ assertEquals(MatchType.GRAM, gram2.getMatching().getType());
+ assertEquals(-1, gram2.getMatching().getGramSize()); // Not set explicitly
+
+ SDField gram3= schema.getConcreteField("gram_3");
+ assertEquals(MatchType.GRAM,gram3.getMatching().getType());
+ 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 | 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());
+ assertEquals(Stemming.NONE, gram1.getStemming());
+
+ List<String> queryCommands = gram1.getQueryCommands();
+ assertEquals(2, queryCommands.size());
+ assertEquals("ngram 1", queryCommands.get(1));
+ }
+
+ @Test
+ public void testInvalidNGramSetting1() throws IOException, ParseException {
+ try {
+ Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram1.sd");
+ fail("Should cause an exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("gram-size can only be set when the matching mode is 'gram'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidNGramSetting2() throws IOException, ParseException {
+ try {
+ Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram2.sd");
+ fail("Should cause an exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("gram-size can only be set when the matching mode is 'gram'", e.getMessage());
+ }
+ }
+
+ @Test
+ public void testInvalidNGramSetting3() throws IOException, ParseException {
+ try {
+ Schema schema = ApplicationBuilder.buildFromFile("src/test/examples/invalidngram3.sd");
+ fail("Should cause an exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("gram matching is not supported with attributes, use 'index' in indexing", e.getMessage());
+ }
+ }
+
+}