Skip to content
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

Adding free-text extension. #655

Merged
merged 6 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

* Add benchmark in CI ([#650](https://github.com/stac-utils/stac-fastapi/pull/650))
* Add Free-text Extension to third party extensions ([#655](https://github.com/stac-utils/stac-fastapi/pull/655))

### Changed

Expand Down
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ nav:
- version: api/stac_fastapi/extensions/version.md
- third_party:
- bulk_transactions: api/stac_fastapi/extensions/third_party/bulk_transactions.md
- free_text: api/stac_fastapi/extensions/third_party/free_text.md
- index: api/stac_fastapi/extensions/third_party/index.md
- stac_fastapi.types:
- module: api/stac_fastapi/types/index.md
Expand Down
2 changes: 2 additions & 0 deletions stac_fastapi/api/stac_fastapi/api/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Application settings."""

import enum


Expand All @@ -23,3 +24,4 @@ class AddOns(enum.Enum):
"""Enumeration of available third party add ons."""

bulk_transaction = "bulk-transaction"
free_text = "free-text"
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
"""stac_api.extensions.third_party module."""

from .bulk_transactions import BulkTransactionExtension
from .free_text import FreeTextExtension

__all__ = ("BulkTransactionExtension",)
__all__ = (
"BulkTransactionExtension",
"FreeTextExtension",
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Query extension module."""

from .free_text import FreeTextExtension

__all__ = ["FreeTextExtension"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Free-text extension."""

from typing import List, Optional

import attr
from fastapi import FastAPI

from stac_fastapi.types.extension import ApiExtension

from .request import FreeTextExtensionGetRequest, FreeTextExtensionPostRequest


@attr.s
class FreeTextExtension(ApiExtension):
"""Free-text Extension.

The Free-text extension adds an additional `q` parameter to `/search` requests which
allows the caller to perform free-text queries against STAC metadata.
https://github.com/stac-api-extensions/freetext-search/README.md
"""

GET = FreeTextExtensionGetRequest
POST = FreeTextExtensionPostRequest

conformance_classes: List[str] = attr.ib(
factory=lambda: [
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
"https://api.stacspec.org/v1.0.0-rc.1/item-search#free-text",
"https://api.stacspec.org/v1.0.0-rc.1/item-search#advanced-free-text",
"https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text",
"https://api.stacspec.org/v1.0.0-rc.1/collection-search#advanced-free-text",
"https://api.stacspec.org/v1.0.0-rc.1/ogcapi-features#free-text",
"https://api.stacspec.org/v1.0.0-rc.1/ogcapi-features#advanced-free-text",
]
)
schema_href: Optional[str] = attr.ib(default=None)

def register(self, app: FastAPI) -> None:
"""Register the extension with a FastAPI application.

Args:
app: target FastAPI application.

Returns:
None
"""
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""Request model for the Free-text extension."""

from typing import Optional

import attr
from pydantic import BaseModel

from stac_fastapi.types.search import APIRequest


@attr.s
class FreeTextExtensionGetRequest(APIRequest):
"""Free-text Extension GET request model."""

q: Optional[str] = attr.ib(default=None)


class FreeTextExtensionPostRequest(BaseModel):
"""Free-text Extension POST request model."""

q: Optional[str] = attr.ib(default=None)
Loading