Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions woudc_api/provider/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ def query(self, offset=0, limit=10, resulttype='results',
if self.index_name.endswith('discovery_metadata'):
limit = limit * 2 # to account for en|fr split

for prop in properties:
values_list = prop[1].split('|')
values = [self._escape_special_chars(value
) for value in values_list]
if len(values) > 1:
values = ' OR '.join(values)
else:
values = values[0]
prop_name = super().mask_prop(prop[0])
q = f'{prop_name}.raw:({values})'

records = super().query(
offset=offset, limit=limit,
resulttype=resulttype, bbox=bbox,
Expand Down Expand Up @@ -198,3 +209,20 @@ def get(self, identifier, **kwargs):
dataset = super().get(identifier2, **kwargs)

return dataset

def _escape_special_chars(self, text):
"""
Escape special characters and spaces in a string for use in
an Elasticsearch query.

:param text: The input string to escape

:returns: The escaped string
"""
LOGGER.debug(f'checking {text} query value for special characters')
special_chars = r'+=&|><!(){}[]^"~*?: '

for char in special_chars:
text = text.replace(char, '\\' + char)

return text
Loading