Skip to content

Commit

Permalink
update OARec q= handling (#912)
Browse files Browse the repository at this point in the history
* update OARec q= handling
* update tests
  • Loading branch information
tomkralidis authored Oct 30, 2023
1 parent b4110a3 commit 45858da
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
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

0 comments on commit 45858da

Please sign in to comment.