Skip to content

Commit

Permalink
Adding free-text extension.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysrevans3 committed Apr 10, 2024
1 parent 53711ec commit 0a10b00
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 1 deletion.
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

### 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: [
"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 Any, Dict, 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[Dict[str, Dict[str, Any]]]

0 comments on commit 0a10b00

Please sign in to comment.