@@ -647,9 +647,9 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
647647 collections = ',' .join (f'"{ x } "' for x in v .split (',' ))
648648 else :
649649 collections = ',' .join (f'"{ x } "' for x in v )
650- query_args .append (f"parentidentifier IN ({ collections } )" )
650+ query_args .append (f"collection IN ({ collections } )" )
651651 elif k == 'anytext' :
652- query_args .append (build_anytext (k , v ))
652+ query_args .append (build_anytext (k , v , self . repository ))
653653 elif k == 'bbox' :
654654 query_args .append (f'BBOX(geometry, { v } )' )
655655 elif k == 'keywords' :
@@ -660,20 +660,24 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
660660 else :
661661 begin , end = v .split ('/' )
662662 if begin != '..' :
663- query_args .append (f'time_begin >= "{ begin } "' )
663+ query_args .append (f'"properties.datetime" >= "{ begin } "' )
664+ #query_args.append(f'time_begin >= "{begin}"')
664665 if end != '..' :
665666 query_args .append (f'time_end <= "{ end } "' )
666667 elif k == 'q' :
667668 if v not in [None , '' ]:
668- query_args .append (build_anytext ('anytext' , v ))
669+ query_args .append (build_anytext ('anytext' , v , self . repository ))
669670 else :
670671 query_args .append (f'{ k } = "{ v } "' )
671672
672673 facets_requested = str2bool (args .get ('facets' , False ))
673674
674675 if collection != 'metadata:main' :
675676 LOGGER .debug ('Adding virtual collection filter' )
676- query_args .append (f'parentidentifier = "{ collection } "' )
677+ query_args .append (f'collection = "{ collection } "' )
678+
679+ if self .repository .dbtype == 'Elasticsearch' :
680+ query_args = [qa .replace ('"' , "'" ) for qa in query_args ]
677681
678682 LOGGER .debug ('Evaluating CQL and other specified filtering parameters' )
679683 if cql_query is not None and query_args :
@@ -771,10 +775,12 @@ def items(self, headers_, json_post_data, args, collection='metadata:main'):
771775 offset = int (args .get ('offset' , 0 ))
772776
773777 if query_parser is not None and cql_query != {}:
778+ LOGGER .debug ('Parsing CQL into AST' )
774779 LOGGER .debug ('Parsing CQL into AST' )
775780 LOGGER .debug (json_post_data )
776781 LOGGER .debug (cql_query )
777782 try :
783+ print ("CQL QUERY" , cql_query )
778784 ast = query_parser (cql_query )
779785 LOGGER .debug (f'Abstract syntax tree: { ast } ' )
780786 except Exception as err :
@@ -1451,13 +1457,13 @@ def record2json(record, url, collection, mode='ogcapi-records'):
14511457
14521458 return record_dict
14531459
1454-
1455- def build_anytext (name , value ):
1460+ def build_anytext (name , value , repository ):
14561461 """
14571462 deconstructs free-text search into CQL predicate(s)
14581463
14591464 :param name: property name
1460- :param name: property value
1465+ :param value: property value
1466+ :param repository: repository object
14611467
14621468 :returns: string of CQL predicate(s)
14631469 """
@@ -1470,17 +1476,30 @@ def build_anytext(name, value):
14701476
14711477 if len (tokens ) == 1 and ' ' not in value : # single term
14721478 LOGGER .debug ('Single term with no spaces' )
1473- return f"{ name } ILIKE '%{ value } %'"
1479+ predicates = [ f"{ name } ILIKE '%{ value } %'" ]
14741480
1475- for token in tokens :
1476- if ' ' in token :
1477- tokens2 = token .split ()
1478- predicates2 = []
1479- for token2 in tokens2 :
1480- predicates2 .append (f"{ name } ILIKE '%{ token2 } %'" )
1481+ else :
1482+ for token in tokens :
1483+ if ' ' in token :
1484+ tokens2 = token .split ()
1485+ predicates2 = []
1486+ for token2 in tokens2 :
1487+ predicates2 .append (f"{ name } ILIKE '%{ token2 } %'" )
14811488
1482- predicates .append ('(' + ' AND ' .join (predicates2 ) + ')' )
1483- else :
1484- predicates .append (f"{ name } ILIKE '%{ token } %'" )
1489+ predicates .append ('(' + ' AND ' .join (predicates2 ) + ')' )
1490+ else :
1491+ predicates .append (f"{ name } ILIKE '%{ token } %'" )
1492+
1493+ if name == 'anytext' and repository .dbtype == 'Elasticsearch' :
1494+ predicates2 = []
1495+ for p in predicates :
1496+ p2 = p
1497+ predicates2 .append (p2 .replace (name , '"properties.title"' ))
1498+ predicates2 .append (p2 .replace (name , '"properties.description"' ))
1499+
1500+ predicates = predicates2
14851501
1486- return f"({ ' OR ' .join (predicates )} )"
1502+ if len (predicates ) == 1 :
1503+ return predicates [0 ]
1504+ else :
1505+ return f"({ ' OR ' .join (predicates )} )"
0 commit comments