Skip to content

Commit

Permalink
[#56] Update repeating subfields indexing logic
Browse files Browse the repository at this point in the history
The previous field names based on indexes didn't allow to retrieve
results easily. We are now flattening all values for the same subfield
to at least get a text hit.

See #281 (comment)
  • Loading branch information
amercader committed May 30, 2024
1 parent a862d77 commit aa23a70
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions ckanext/dcat/plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,18 @@ def before_dataset_index(self, dataset_dict):
pass

if schema:
# TODO: https://github.com/ckan/ckanext-dcat/pull/281#discussion_r1610549936
for field in schema['dataset_fields']:
if field['field_name'] in dataset_dict and 'repeating_subfields' in field:
for index, item in enumerate(dataset_dict[field['field_name']]):
for item in dataset_dict[field['field_name']]:
for key in item:
value = dataset_dict[field['field_name']][index][key]
value = item[key]
if not isinstance(value, dict):
# Index a flattened version
new_key = f'{field["field_name"]}_{index}_{key}'
dataset_dict[new_key] = value
new_key = f'{field["field_name"]}__{key}'
if not dataset_dict.get(new_key):
dataset_dict[new_key] = ""
dataset_dict[new_key] += " " + value

dataset_dict.pop(field['field_name'], None)

return dataset_dict
Expand Down

0 comments on commit aa23a70

Please sign in to comment.