-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding free-text extension. * Adding pull request to change log. * q parameter should be string for post. * Removing unneeded imports. * split free-text ext --------- Co-authored-by: vincentsarago <[email protected]>
- Loading branch information
1 parent
c55c253
commit fe4d0df
Showing
8 changed files
with
523 additions
and
0 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
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", | ||
) |
Oops, something went wrong.
fe4d0df
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible performance regression was detected for benchmark 'STAC FastAPI Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.30
.Items With Model validation (200)
44.67664296001307
iter/sec (stddev: 0.016665893098592833
)61.54567911069334
iter/sec (stddev: 0.008523711212090172
)1.38
This comment was automatically generated by workflow using github-action-benchmark.