Skip to content

convert all uses of query to filter #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ For changes, see the [Changelog](CHANGELOG.md).
To install the classes in your local Python env, run:

```shell
cd stac_fastapi/elasticsearch
pip install -e '.[dev]'
pip install -e 'stac_fastapi/elasticsearch[dev]'
```

### Pre-commit
Expand Down
47 changes: 21 additions & 26 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ class CoreClient(AsyncBaseCoreClient):
async def all_collections(self, **kwargs) -> Collections:
"""Read all collections from the database."""
base_url = str(kwargs["request"].base_url)
serialized_collections = await self.database.get_all_collections(
base_url=base_url
)
collection_list = await self.database.get_all_collections(base_url=base_url)

links = [
{
Expand All @@ -71,10 +69,8 @@ async def all_collections(self, **kwargs) -> Collections:
"href": urljoin(base_url, "collections"),
},
]
collection_list = Collections(
collections=serialized_collections or [], links=links
)
return collection_list

return Collections(collections=collection_list, links=links)

@overrides
async def get_collection(self, collection_id: str, **kwargs) -> Collection:
Expand All @@ -91,21 +87,22 @@ async def item_collection(
links = []
base_url = str(kwargs["request"].base_url)

serialized_children, count = await self.database.get_item_collection(
items, maybe_count = await self.database.get_collection_items(
collection_id=collection_id, limit=limit, base_url=base_url
)

context_obj = None
if self.extension_is_enabled("ContextExtension"):
context_obj = {
"returned": count if count is not None and count < limit else limit,
"returned": len(items),
"limit": limit,
"matched": count,
}
if maybe_count is not None:
context_obj["matched"] = maybe_count

return ItemCollection(
type="FeatureCollection",
features=serialized_children,
features=items,
links=links,
context=context_obj,
)
Expand Down Expand Up @@ -207,29 +204,29 @@ async def post_search(
) -> ItemCollection:
"""POST search catalog."""
base_url = str(kwargs["request"].base_url)
search = self.database.create_search()
search = self.database.make_search()

if search_request.query:
for (field_name, expr) in search_request.query.items():
field = "properties__" + field_name
for (op, value) in expr.items():
search = self.database.create_query_filter(
search = self.database.apply_stacql_filter(
search=search, op=op, field=field, value=value
)

if search_request.ids:
search = self.database.search_ids(
search = self.database.apply_ids_filter(
search=search, item_ids=search_request.ids
)

if search_request.collections:
search = self.database.filter_collections(
search = self.database.apply_collections_filter(
search=search, collection_ids=search_request.collections
)

if search_request.datetime:
datetime_search = self._return_date(search_request.datetime)
search = self.database.search_datetime(
search = self.database.apply_datetime_filter(
search=search, datetime_search=datetime_search
)

Expand All @@ -238,24 +235,22 @@ async def post_search(
if len(bbox) == 6:
bbox = [bbox[0], bbox[1], bbox[3], bbox[4]]

search = self.database.search_bbox(search=search, bbox=bbox)
search = self.database.apply_bbox_filter(search=search, bbox=bbox)

if search_request.intersects:
self.database.search_intersects(
self.database.apply_intersects_filter(
search=search, intersects=search_request.intersects
)

if search_request.sortby:
for sort in search_request.sortby:
if sort.field == "datetime":
sort.field = "properties__datetime"
search = self.database.sort_field(
search = self.database.apply_sort(
search=search, field=sort.field, direction=sort.direction
)

count = await self.database.search_count(search=search)

response_features = await self.database.execute_search(
response_features, maybe_count = await self.database.execute_search(
search=search, limit=search_request.limit, base_url=base_url
)

Expand Down Expand Up @@ -289,16 +284,16 @@ async def post_search(
context_obj = None
if self.extension_is_enabled("ContextExtension"):
context_obj = {
"returned": count if count < limit else limit,
"returned": len(response_features),
"limit": limit,
"matched": count,
}
if maybe_count is not None:
context_obj["matched"] = maybe_count

links = []
return ItemCollection(
type="FeatureCollection",
features=response_features,
links=links,
links=[],
context=context_obj,
)

Expand Down
Loading