diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py index d94f1601..fbfb51ce 100644 --- a/tests/unit/test_package.py +++ b/tests/unit/test_package.py @@ -1963,6 +1963,49 @@ def test_document_expiry(self): self.assertTrue(validate_services(application_package.services_to_text)) +class TestPredicateField(unittest.TestCase): + def setUp(self): + self.app_package = ApplicationPackage(name="predicatetest") + + # Add a document with a predicate field + self.app_package.schema.add_fields( + Field(name="id", type="string", indexing=["attribute", "summary"]), + Field( + name="predicate_field", + type="predicate", + indexing=["attribute"], + index={ + "arity": 2, + "lower-bound": 3, + "upper-bound": 200, + "dense-posting-list-threshold": 0.25, + }, + ), + ) + + def test_predicate_field_schema(self): + expected_result = """schema predicatetest { + document predicatetest { + field id type string { + indexing: attribute | summary + } + field predicate_field type predicate { + indexing: attribute + index { + arity: 2 + lower-bound: 3 + upper-bound: 200 + dense-posting-list-threshold: 0.25 + } + } + } +}""" + print() + print(self.app_package.schema.schema_to_text) + print() + print(expected_result) + self.assertEqual(self.app_package.schema.schema_to_text, expected_result) + class TestRankProfileCustomSettings(unittest.TestCase): def test_rank_profile_with_filter_and_weakand(self): # Create a minimal schema with a dummy document to allow rank profile rendering. diff --git a/vespa/templates/macros.txt b/vespa/templates/macros.txt index 8ca7b930..22ff0a52 100644 --- a/vespa/templates/macros.txt +++ b/vespa/templates/macros.txt @@ -6,8 +6,16 @@ field {{ field.name }} type {{ field.type }} { indexing: {{ field.indexing_to_text }} {% endif %} {% if field.index %} + {% if field.index is mapping %} + index { + {% for key, value in field.index.items() %} + {{ key }}: {{ value }} + {% endfor %} + } + {% else %} index: {{ field.index }} {% endif %} + {% endif %} {% if field.ann or field.attribute %} attribute { {% if field.ann %} diff --git a/vespa/templates/schema.txt b/vespa/templates/schema.txt index abc4a4d9..456ff6f9 100644 --- a/vespa/templates/schema.txt +++ b/vespa/templates/schema.txt @@ -17,8 +17,16 @@ schema {{ schema_name }}{% if schema.inherits %} inherits {{ schema.inherits }}{ indexing: {{ field.indexing_to_text }} {% endif %} {% if field.index %} + {% if field.index is mapping %} + index { + {% for key, value in field.index.items() %} + {{ key }}: {{ value }} + {% endfor %} + } + {% else %} index: {{ field.index }} {% endif %} + {% endif %} {% if field.ann or field.attribute %} attribute { {% if field.ann %}