Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update OARec q= handling #912

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions pycsw/ogc/api/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,13 +1209,25 @@ def build_anytext(name, value):
:returns: string of CQL predicate(s)
"""

LOGGER.debug(f'Name: {name}')
LOGGER.debug(f'Value: {value}')

predicates = []
tokens = value.split()
tokens = value.split(',')

if len(tokens) == 1: # single term
if len(tokens) == 1 and ' ' not in value: # single term
LOGGER.debug(f'Single term with no spaces')
return f"{name} ILIKE '%{value}%'"

for token in tokens:
predicates.append(f"{name} ILIKE '%{token}%'")
if ' ' in token:
tokens2 = token.split()
predicates2 = []
for token2 in tokens2:
predicates2.append(f"{name} ILIKE '%{token2}%'")

predicates.append('(' + ' AND '.join(predicates2) + ')')
else:
predicates.append(f"{name} ILIKE '%{token}%'")

return f"({' AND '.join(predicates)})"
return f"({' OR '.join(predicates)})"
24 changes: 24 additions & 0 deletions tests/functionaltests/suites/oarec/test_oarec_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ def test_items(config):
assert content['numberReturned'] == 1
assert len(content['features']) == content['numberReturned']

params = {'q': 'Lorem ipsum'}
content = json.loads(api.items({}, None, params)[2])
assert content['numberMatched'] == 2
assert content['numberReturned'] == 2
assert len(content['features']) == content['numberReturned']

params = {'q': 'Lorem,ipsum'}
content = json.loads(api.items({}, None, params)[2])
assert content['numberMatched'] == 6
assert content['numberReturned'] == 6
assert len(content['features']) == content['numberReturned']

params = {'q': 'Lorem ipsum purus'}
content = json.loads(api.items({}, None, params)[2])
assert content['numberMatched'] == 0
assert content['numberReturned'] == 0
assert len(content['features']) == content['numberReturned']

params = {'q': 'Lorem ipsum,purus'}
content = json.loads(api.items({}, None, params)[2])
assert content['numberMatched'] == 4
assert content['numberReturned'] == 4
assert len(content['features']) == content['numberReturned']

ids = [
'urn:uuid:19887a8a-f6b0-4a63-ae56-7fba0e17801f',
'urn:uuid:1ef30a8b-876d-4828-9246-c37ab4510bbd'
Expand Down
Loading