-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
537 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
stac_fastapi/extensions/stac_fastapi/extensions/core/collection_search/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"""Collection-Search extension module.""" | ||
|
||
from .collection_search import CollectionSearchExtension | ||
from .collection_search import CollectionSearchExtension, ConformanceClasses | ||
|
||
__all__ = ["CollectionSearchExtension"] | ||
__all__ = ["CollectionSearchExtension", "ConformanceClasses"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
stac_fastapi/extensions/stac_fastapi/extensions/core/free_text/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Query extension module.""" | ||
|
||
from .free_text import ( | ||
FreeTextAdvancedExtension, | ||
FreeTextConformanceClasses, | ||
FreeTextExtension, | ||
) | ||
|
||
__all__ = [ | ||
"FreeTextExtension", | ||
"FreeTextAdvancedExtension", | ||
"FreeTextConformanceClasses", | ||
] |
110 changes: 110 additions & 0 deletions
110
stac_fastapi/extensions/stac_fastapi/extensions/core/free_text/free_text.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
"""Free-text extension.""" | ||
|
||
from enum import Enum | ||
from typing import List, Optional | ||
|
||
import attr | ||
from fastapi import FastAPI | ||
|
||
from stac_fastapi.types.extension import ApiExtension | ||
|
||
from .request import ( | ||
FreeTextAdvancedExtensionGetRequest, | ||
FreeTextAdvancedExtensionPostRequest, | ||
FreeTextExtensionGetRequest, | ||
FreeTextExtensionPostRequest, | ||
) | ||
|
||
|
||
class FreeTextConformanceClasses(str, Enum): | ||
"""Conformance classes for the Free-Text extension. | ||
See https://github.com/stac-api-extensions/freetext-search | ||
""" | ||
|
||
# https://github.com/stac-api-extensions/freetext-search?tab=readme-ov-file#basic | ||
SEARCH = "https://api.stacspec.org/v1.0.0-rc.1/item-search#free-text" | ||
COLLECTIONS = "https://api.stacspec.org/v1.0.0-rc.1/collection-search#free-text" | ||
ITEMS = "https://api.stacspec.org/v1.0.0-rc.1/ogcapi-features#free-text" | ||
|
||
# https://github.com/stac-api-extensions/freetext-search?tab=readme-ov-file#advanced | ||
SEARCH_ADVANCED = ( | ||
"https://api.stacspec.org/v1.0.0-rc.1/item-search#advanced-free-text" | ||
) | ||
COLLECTIONS_ADVANCED = ( | ||
"https://api.stacspec.org/v1.0.0-rc.1/collection-search#advanced-free-text" | ||
) | ||
ITEMS_ADVANCED = ( | ||
"https://api.stacspec.org/v1.0.0-rc.1/ogcapi-features#advanced-free-text" | ||
) | ||
|
||
|
||
@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?tab=readme-ov-file#basic | ||
""" | ||
|
||
GET = FreeTextExtensionGetRequest | ||
POST = FreeTextExtensionPostRequest | ||
|
||
conformance_classes: List[str] = attr.ib( | ||
default=[ | ||
FreeTextConformanceClasses.SEARCH, | ||
FreeTextConformanceClasses.COLLECTIONS, | ||
FreeTextConformanceClasses.ITEMS, | ||
] | ||
) | ||
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 | ||
|
||
|
||
@attr.s | ||
class FreeTextAdvancedExtension(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?tab=readme-ov-file#advanced | ||
""" | ||
|
||
GET = FreeTextAdvancedExtensionGetRequest | ||
POST = FreeTextAdvancedExtensionPostRequest | ||
|
||
conformance_classes: List[str] = attr.ib( | ||
default=[ | ||
FreeTextConformanceClasses.SEARCH_ADVANCED, | ||
FreeTextConformanceClasses.COLLECTIONS_ADVANCED, | ||
FreeTextConformanceClasses.ITEMS_ADVANCED, | ||
] | ||
) | ||
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 |
64 changes: 64 additions & 0 deletions
64
stac_fastapi/extensions/stac_fastapi/extensions/core/free_text/request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Request model for the Free-text extension.""" | ||
|
||
from typing import List, Optional | ||
|
||
import attr | ||
from fastapi import Query | ||
from pydantic import BaseModel, Field | ||
from typing_extensions import Annotated | ||
|
||
from stac_fastapi.types.search import APIRequest, str2list | ||
|
||
|
||
def _ft_converter( | ||
val: Annotated[ | ||
Optional[str], | ||
Query( | ||
description="Parameter to perform free-text queries against STAC metadata", | ||
json_schema_extra={ | ||
"example": "ocean,coast", | ||
}, | ||
), | ||
] = None, | ||
) -> Optional[List[str]]: | ||
return str2list(val) | ||
|
||
|
||
@attr.s | ||
class FreeTextExtensionGetRequest(APIRequest): | ||
"""Free-text Extension GET request model.""" | ||
|
||
q: Optional[List[str]] = attr.ib(default=None, converter=_ft_converter) | ||
|
||
|
||
class FreeTextExtensionPostRequest(BaseModel): | ||
"""Free-text Extension POST request model.""" | ||
|
||
q: Optional[List[str]] = Field( | ||
None, | ||
description="Parameter to perform free-text queries against STAC metadata", | ||
) | ||
|
||
|
||
@attr.s | ||
class FreeTextAdvancedExtensionGetRequest(APIRequest): | ||
"""Free-text Extension GET request model.""" | ||
|
||
q: Annotated[ | ||
Optional[str], | ||
Query( | ||
description="Parameter to perform free-text queries against STAC metadata", | ||
json_schema_extra={ | ||
"example": "ocean,coast", | ||
}, | ||
), | ||
] = attr.ib(default=None) | ||
|
||
|
||
class FreeTextAdvancedExtensionPostRequest(BaseModel): | ||
"""Free-text Extension POST request model.""" | ||
|
||
q: Optional[str] = Field( | ||
None, | ||
description="Parameter to perform free-text queries against STAC metadata", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.