diff options
Diffstat (limited to 'config-model/src/test/java/com/yahoo/schema')
-rw-r--r-- | config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java b/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java index 61d636d911f..852f567ccfa 100644 --- a/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java +++ b/config-model/src/test/java/com/yahoo/schema/derived/VsmFieldsTestCase.java @@ -6,6 +6,7 @@ import com.yahoo.config.model.deploy.TestProperties; import com.yahoo.config.model.test.MockApplicationPackage; import com.yahoo.document.DataType; import com.yahoo.documentmodel.NewDocumentReferenceDataType; +import com.yahoo.schema.ApplicationBuilder; import com.yahoo.schema.Schema; import com.yahoo.schema.document.Case; import com.yahoo.schema.document.MatchType; @@ -13,9 +14,14 @@ import com.yahoo.schema.document.Matching; import com.yahoo.schema.document.SDDocumentType; import com.yahoo.schema.document.SDField; import com.yahoo.schema.document.TemporarySDField; +import com.yahoo.schema.parser.ParseException; import com.yahoo.vespa.config.search.vsm.VsmfieldsConfig; import org.junit.jupiter.api.Test; +import java.util.HashSet; +import java.util.Set; + +import static com.yahoo.config.model.test.TestUtil.joinLines; import static org.junit.jupiter.api.Assertions.assertEquals; /** @@ -77,4 +83,72 @@ public class VsmFieldsTestCase { testIndexMatching(new Matching(MatchType.WORD).setCase(Case.CASED), VsmfieldsConfig.Fieldspec.Normalize.NONE, "word"); } + + private static Set<String> getIndexes(VsmfieldsConfig config, String field) { + var indexes = new HashSet<String>(); + var doctype = config.documenttype(0); + for (var index : doctype.index()) { + for (var indexField : index.field()) { + if (field.equals(indexField.name())) { + indexes.add(index.name()); + break; + } + } + } + return indexes; + } + + @Test + void deriveIndexFromNestedAttributes() throws ParseException { + String sd = joinLines( + "schema test {", + " document test {", + " field map_field type map<string,int> {", + " indexing: summary", + " struct-field key { indexing: attribute }", + " struct-field value { indexing: attribute }", + " }", + " }", + "}"); + var schema = ApplicationBuilder.createFromString(sd).getSchema(); + var config = vsmfieldsConfig(schema); + assertEquals(Set.of("map_field", "map_field.key"), getIndexes(config, "map_field.key")); + assertEquals(Set.of("map_field", "map_field.value"), getIndexes(config, "map_field.value")); + } + + @Test + void deriveIndexFromIndexStatement() throws ParseException { + String sd = joinLines( + "schema test {", + " document test {", + " field map_field type map<string,int> {", + " indexing: summary | index", + " }", + " }", + "}"); + var schema = ApplicationBuilder.createFromString(sd).getSchema(); + var config = vsmfieldsConfig(schema); + assertEquals(Set.of("map_field", "map_field.key"), getIndexes(config, "map_field.key")); + assertEquals(Set.of("map_field", "map_field.value"), getIndexes(config, "map_field.value")); + } + + @Test + void positionFieldTypeBlocksderivingOfIndexFromNestedAttributes() throws ParseException { + String sd = joinLines( + "schema test {", + " document test {", + " field pos type position {", + " indexing: attribute | summary", + " struct-field x { indexing: attribute }", + " struct-field y { indexing: attribute }", + " }", + " }", + "}"); + var schema = ApplicationBuilder.createFromString(sd).getSchema(); + var config = vsmfieldsConfig(schema); + assertEquals(Set.of("pos"), getIndexes(config, "pos")); + assertEquals(Set.of(), getIndexes(config, "pos.x")); + assertEquals(Set.of(), getIndexes(config, "pos.y")); + } + } |