@@ -373,6 +373,8 @@ async def item_collection(
373373 limit : Optional [int ] = None ,
374374 page : Optional [str ] = None ,
375375 sortby : Optional [list [str ]] = None ,
376+ filter_expr : Optional [str ] = None ,
377+ filter_lang : Optional [str ] = "cql2-text" ,
376378 ** kwargs : Any ,
377379 ) -> ItemCollection :
378380 """
@@ -386,6 +388,9 @@ async def item_collection(
386388 :param datetime: Date and time range to filter the items.
387389 :param limit: Maximum number of items to return.
388390 :param page: Page token for pagination.
391+ :param sortby: List of fields to sort the results by.
392+ :param filter_expr: CQL filter to apply to the search.
393+ :param filter_lang: Language of the filter (default is "cql2-text").
389394 :param kwargs: Additional arguments.
390395 :returns: An ItemCollection.
391396 :raises NotFoundError: If the collection does not exist.
@@ -405,6 +410,9 @@ async def item_collection(
405410 sortby_converted = get_sortby_to_post (sortby )
406411 base_args ["sortby" ] = cast (Any , sortby_converted )
407412
413+ if filter_expr :
414+ add_filter_to_args (base_args , filter_lang , filter_expr )
415+
408416 clean = {}
409417 for k , v in base_args .items ():
410418 if v is not None and v != []:
@@ -481,12 +489,7 @@ def get_search(
481489 base_args ["datetime" ] = format_datetime_range (datetime )
482490
483491 if filter_expr :
484- if filter_lang == "cql2-text" :
485- filter_expr = to_cql2 (parse_cql2_text (filter_expr ))
486- filter_lang = "cql2-json"
487-
488- base_args ["filter" ] = str2json ("filter_expr" , filter_expr )
489- base_args ["filter_lang" ] = "cql2-json"
492+ add_filter_to_args (base_args , filter_lang , filter_expr )
490493
491494 # Remove None values from dict
492495 clean = {}
@@ -766,3 +769,18 @@ def eodag_search_next_page(dag, eodag_args):
766769 logger .info ("StopIteration encountered during next page search." )
767770 search_result = SearchResult ([])
768771 return search_result
772+
773+
774+ def add_filter_to_args (base_args : dict [str , Any ], filter_lang : Optional [str ], filter_expr : Optional [str ]):
775+ """Parse the filter from the query and add to arguments
776+
777+ :param base_args:
778+ :param filter_expr: CQL filter to apply to the search.
779+ :param filter_lang: Language of the filter (default is "cql2-text").
780+ """
781+ if filter_lang == "cql2-text" :
782+ filter_expr = to_cql2 (parse_cql2_text (filter_expr ))
783+ filter_lang = "cql2-json"
784+
785+ base_args ["filter" ] = str2json ("filter_expr" , filter_expr )
786+ base_args ["filter_lang" ] = "cql2-json"
0 commit comments