make TinyDB q= queries case-insensitive (#792)
* make TinyDB q= queries case-insensitive * make TinyDB q= queries case-insensitive * optimize nocase tests * optimize nocase tests
This commit is contained in:
@@ -29,6 +29,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re # noqa
|
||||
|
||||
from tinydb import TinyDB, Query
|
||||
|
||||
@@ -156,7 +157,7 @@ class TinyDBCatalogueProvider(BaseProvider):
|
||||
|
||||
if q is not None:
|
||||
for t in q.split():
|
||||
QUERY.append("(Q.properties['_metadata-anytext'].search('{}'))".format(t)) # noqa
|
||||
QUERY.append("(Q.properties['_metadata-anytext'].search('{}', flags=re.IGNORECASE))".format(t)) # noqa
|
||||
|
||||
QUERY_STRING = '&'.join(QUERY)
|
||||
LOGGER.debug('QUERY_STRING: {}'.format(QUERY_STRING))
|
||||
|
||||
@@ -64,10 +64,11 @@ def test_query(config):
|
||||
assert results['features'][0]['id'] == 'e5a71860-827c-453f-990e-0e0ba0ee67bb' # noqa
|
||||
assert results['features'][0]['properties']['type'] == 'RI_622'
|
||||
|
||||
results = p.query(q='crops')
|
||||
assert len(results['features']) == 6
|
||||
assert results['numberMatched'] == 6
|
||||
assert results['numberReturned'] == 6
|
||||
for term in ['crops', 'Crops', 'CROPS', 'CrOpS', 'CROps', 'CRops']:
|
||||
results = p.query(q=term)
|
||||
assert len(results['features']) == 6
|
||||
assert results['numberMatched'] == 6
|
||||
assert results['numberReturned'] == 6
|
||||
|
||||
results = p.query(q='crops barley')
|
||||
assert len(results['features']) == 2
|
||||
|
||||
Reference in New Issue
Block a user