Skip to content

Commit

Permalink
[#56] Index subfields as extras_ Solr field
Browse files Browse the repository at this point in the history
As this is a `text` field that allows free text search
  • Loading branch information
amercader committed Jun 13, 2024
1 parent ad35359 commit b600493
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ckanext/dcat/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
28 changes: 26 additions & 2 deletions ckanext/dcat/tests/test_scheming_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b600493

Please sign in to comment.