@@ -401,11 +401,45 @@ def _add_extra_fields(self, json_data: dict) -> dict:
401
401
402
402
return json_data
403
403
404
+ def _prepare_q_param_with_spaces (self , s : str ) -> str :
405
+ """
406
+ Prepare a search statement for the search term `s`.
407
+ The term `s` might have spaces.
408
+
409
+ Examples (f is shorthand for Q.properties["_metadata-anytext"]):
410
+ +---------------+--------------------+
411
+ | search term | TinyDB search |
412
+ +---------------+--------------------+
413
+ | 'aa' | f.search('aa') |
414
+ | 'aa bb' | f.search('aa +bb') |
415
+ | ' aa bb ' | f.search('aa +bb') |
416
+ +---------------+--------------------+
417
+ """
418
+ return 'Q.properties["_metadata-anytext"].search("' \
419
+ + ' +' .join (s .split ()) \
420
+ + '", flags=re.IGNORECASE)'
421
+
404
422
def _add_search_query (self , query : list , search_term : str = None ) -> str :
405
- if search_term is not None :
423
+ """
424
+ Create a search query according to the OGC API - Records specification.
425
+
426
+ https://docs.ogc.org/is/20-004r1/20-004r1.html (Listing 14)
427
+
428
+ Examples (f is shorthand for Q.properties["_metadata-anytext"]):
429
+ +-------------+-----------------------------------+
430
+ | search term | TinyDB search |
431
+ +-------------+-----------------------------------+
432
+ | 'aa' | f.search('aa') |
433
+ | 'aa,bb' | f.search('aa')|f.search('bb') |
434
+ | 'aa,bb cc' | f.search('aa')|f.search('bb +cc') |
435
+ +-------------+-----------------------------------+
436
+ """
437
+ if search_term is not None and len (search_term ) > 0 :
406
438
LOGGER .debug ('catalogue q= query' )
407
- for t in search_term .split ():
408
- query .append (f"(Q.properties['_metadata-anytext'].search('{ t } ', flags=re.IGNORECASE))" ) # noqa
439
+ terms = [s for s in search_term .split (',' ) if len (s ) > 0 ]
440
+ query .append ('|' .join (
441
+ [self ._prepare_q_param_with_spaces (t ) for t in terms ]
442
+ ))
409
443
410
444
return query
411
445
0 commit comments