diff --git a/ckanext/dcat/plugins/__init__.py b/ckanext/dcat/plugins/__init__.py index 087eb2f7..2aef170b 100644 --- a/ckanext/dcat/plugins/__init__.py +++ b/ckanext/dcat/plugins/__init__.py @@ -173,7 +173,7 @@ def before_dataset_index(self, dataset_dict): value = item[key] if not isinstance(value, dict): # Index a flattened version - new_key = f'{field["field_name"]}__{key}' + new_key = f'extras_{field["field_name"]}__{key}' if not dataset_dict.get(new_key): dataset_dict[new_key] = value else: diff --git a/ckanext/dcat/tests/test_scheming_support.py b/ckanext/dcat/tests/test_scheming_support.py index f39f0fdd..913cb4a9 100644 --- a/ckanext/dcat/tests/test_scheming_support.py +++ b/ckanext/dcat/tests/test_scheming_support.py @@ -769,12 +769,36 @@ def test_repeating_subfields_index(self): # Dict sent to Solr search_dict = m.mock_calls[1].kwargs["docs"][0] - assert search_dict["contact__name"] == "Contact 1 Contact 2" + assert search_dict["extras_contact__name"] == "Contact 1 Contact 2" assert ( - search_dict["contact__email"] + search_dict["extras_contact__email"] == "contact1@example.org contact2@example.org" ) + def test_repeating_subfields_search(self): + + dataset_dict = { + # Core fields + "name": "test-dataset", + "title": "Test DCAT dataset", + "notes": "Some notes", + # Repeating subfields + "contact": [ + {"name": "Contact 1", "email": "contact1@example.org"}, + {"name": "Contact 2", "email": "contact2@example.org"}, + ], + } + + dataset = call_action("package_create", **dataset_dict) + + result = call_action("package_search", q="Contact 2") + + assert result["results"][0]["id"] == dataset["id"] + + result = call_action("package_search", q="Contact 3") + + assert result["count"] == 0 + def test_spatial_field(self): dataset_dict = {