|
49 | 49 | from eodag.utils.exceptions import NoMatchingCollection as EodagNoMatchingCollection |
50 | 50 | from stac_fastapi.eodag.client import CustomCoreClient |
51 | 51 | from stac_fastapi.eodag.config import get_settings |
52 | | -from stac_fastapi.eodag.constants import DEFAULT_ITEMS_PER_PAGE |
| 52 | +from stac_fastapi.eodag.constants import DEFAULT_LIMIT |
53 | 53 | from stac_fastapi.eodag.cql_evaluate import EodagEvaluator |
54 | 54 | from stac_fastapi.eodag.errors import NoMatchingCollection, ResponseSearchError |
55 | 55 | from stac_fastapi.eodag.models.item import create_stac_item |
@@ -588,67 +588,48 @@ def prepare_search_base_args(search_request: BaseSearchPostRequest, model: type[ |
588 | 588 | :param model: the model used to validate stac metadata |
589 | 589 | :returns: a dictionary containing arguments for the eodag search |
590 | 590 | """ |
591 | | - base_args = ( |
592 | | - { |
593 | | - "token": search_request.token, |
594 | | - "items_per_page": search_request.limit, |
595 | | - "raise_errors": False, |
596 | | - "count": get_settings().count, |
597 | | - } |
598 | | - if search_request.ids is None |
599 | | - else {} |
600 | | - ) |
601 | | - |
602 | | - if search_request.spatial_filter is not None: |
603 | | - base_args["geom"] = search_request.spatial_filter.wkt |
604 | | - # Also check datetime to bypass persistent dates between searches |
605 | | - # until https://github.com/stac-utils/stac-pydantic/pull/171 is merged |
606 | | - if search_request.datetime is not None and search_request.start_date is not None: |
607 | | - base_args["start"] = search_request.start_date.isoformat().replace("+00:00", "Z") |
608 | | - if search_request.datetime is not None and search_request.end_date is not None: |
609 | | - base_args["end"] = search_request.end_date.isoformat().replace("+00:00", "Z") |
| 591 | + if search_request.ids is None: |
| 592 | + base_args = search_request.model_dump() |
| 593 | + base_args["raise_errors"] = False |
| 594 | + base_args["count"] = get_settings().count |
| 595 | + else: |
| 596 | + base_args = {} |
610 | 597 |
|
611 | 598 | # parse "sortby" search request attribute if it exists to make it work for an eodag search |
612 | 599 | sort_by = {} |
613 | | - if sortby := getattr(search_request, "sortby", None): |
614 | | - sort_by_special_fields = { |
615 | | - "start": "start_datetime", |
616 | | - "end": "end_datetime", |
617 | | - } |
| 600 | + if sortby := base_args.pop("sortby", None): |
618 | 601 | param_tuples = [] |
619 | 602 | for param in sortby: |
620 | | - dumped_param = param.model_dump(mode="json") |
621 | 603 | param_tuples.append( |
622 | 604 | ( |
623 | | - sort_by_special_fields.get( |
624 | | - model.to_eodag(dumped_param["field"]), |
625 | | - model.to_eodag(dumped_param["field"]), |
626 | | - ), |
627 | | - dumped_param["direction"], |
| 605 | + model.to_eodag(param["field"]), |
| 606 | + param["direction"], |
628 | 607 | ) |
629 | 608 | ) |
630 | 609 | sort_by["sort_by"] = param_tuples |
631 | 610 |
|
632 | 611 | eodag_query = {} |
633 | | - if query_attr := getattr(search_request, "query", None): |
| 612 | + if query_attr := base_args.pop("query", None): |
634 | 613 | parsed_query = parse_query(query_attr) |
635 | 614 | eodag_query = {model.to_eodag(k): v for k, v in parsed_query.items()} |
636 | 615 |
|
637 | 616 | # get the extracted CQL2 properties dictionary if the CQL2 filter exists |
638 | 617 | eodag_filter = {} |
639 | | - if f := getattr(search_request, "filter_expr", None): |
| 618 | + base_args.pop("filter_lang", None) |
| 619 | + if f := base_args.pop("filter_expr", None): |
640 | 620 | parsed_filter = parse_cql2(f) |
641 | 621 | eodag_filter = {model.to_eodag(k): v for k, v in parsed_filter.items()} |
642 | 622 |
|
643 | 623 | # EODAG search support a single collection |
644 | | - if search_request.collections: |
645 | | - base_args["collection"] = search_request.collections[0] |
| 624 | + if collections := base_args.pop("collections", search_request.collections): |
| 625 | + base_args["collection"] = collections[0] |
646 | 626 |
|
647 | 627 | if search_request.ids: |
648 | 628 | base_args["ids"] = search_request.ids |
649 | 629 |
|
650 | 630 | # merge all eodag search arguments |
651 | 631 | base_args = base_args | sort_by | eodag_filter | eodag_query |
| 632 | + base_args = {k: v for k, v in base_args.items() if v is not None} # remove parameters with value None |
652 | 633 |
|
653 | 634 | return base_args |
654 | 635 |
|
@@ -774,7 +755,7 @@ def eodag_search_next_page(dag, eodag_args): |
774 | 755 | next_page_token_key = getattr(search_plugin.config, "pagination", {}).get("next_page_token_key", "page") |
775 | 756 | eodag_args.pop("count", None) |
776 | 757 | search_result = SearchResult( |
777 | | - [EOProduct(provider, {"id": "_"})] * int(eodag_args.get("items_per_page", DEFAULT_ITEMS_PER_PAGE)), |
| 758 | + [EOProduct(provider, {"id": "_"})] * int(eodag_args.get("limit", DEFAULT_LIMIT)), |
778 | 759 | next_page_token=next_page_token, |
779 | 760 | next_page_token_key=next_page_token_key, |
780 | 761 | search_params=eodag_args, |
|
0 commit comments