Skip to content

Commit c0d5aac

Browse files
committed
create filter package
1 parent 9a68168 commit c0d5aac

File tree

6 files changed

+330
-294
lines changed

6 files changed

+330
-294
lines changed

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py

Lines changed: 0 additions & 294 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# STAC FastAPI Filter Package
2+
3+
This package contains shared filter extension functionality used by both the Elasticsearch and OpenSearch
4+
implementations of STAC FastAPI. It helps reduce code duplication and ensures consistent behavior
5+
between the two implementations.
6+
7+
## Package Structure
8+
9+
The filter package is organized into three main modules:
10+
11+
- **cql2.py**: Contains functions for converting CQL2 patterns to Elasticsearch/OpenSearch compatible formats
12+
- [cql2_like_to_es](cci:1://file:///home/computer/Code/stac-fastapi-elasticsearch-opensearch/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py:59:0-75:5): Converts CQL2 "LIKE" characters to Elasticsearch "wildcard" characters
13+
- [_replace_like_patterns](cci:1://file:///home/computer/Code/stac-fastapi-elasticsearch-opensearch/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py:51:0-56:71): Helper function for pattern replacement
14+
15+
- **transform.py**: Contains functions for transforming CQL2 queries to Elasticsearch/OpenSearch query DSL
16+
- [to_es_field](cci:1://file:///home/computer/Code/stac-fastapi-elasticsearch-opensearch/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py:83:0-93:47): Maps field names using queryables mapping
17+
- [to_es](cci:1://file:///home/computer/Code/stac-fastapi-elasticsearch-opensearch/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py:96:0-201:13): Transforms CQL2 query structures to Elasticsearch/OpenSearch query DSL
18+
19+
- **client.py**: Contains the base filter client implementation
20+
- [EsAsyncBaseFiltersClient](cci:2://file:///home/computer/Code/stac-fastapi-elasticsearch-opensearch/stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/filter.py:209:0-293:25): Base class for implementing the STAC filter extension
21+
22+
## Usage
23+
24+
Import the necessary components from the filter package:
25+
26+
```python
27+
from stac_fastapi.sfeos_helpers.filter import cql2_like_to_es, to_es, EsAsyncBaseFiltersClient
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""Shared filter extension methods for stac-fastapi elasticsearch and opensearch backends.
2+
3+
This module provides shared functionality for implementing the STAC API Filter Extension
4+
with Elasticsearch and OpenSearch. It includes:
5+
6+
1. Functions for converting CQL2 queries to Elasticsearch/OpenSearch query DSL
7+
2. Helper functions for field mapping and query transformation
8+
3. Base implementation of the AsyncBaseFiltersClient for Elasticsearch/OpenSearch
9+
10+
The filter package is organized as follows:
11+
- cql2.py: CQL2 pattern conversion helpers
12+
- transform.py: Query transformation functions
13+
- client.py: Filter client implementation
14+
15+
When adding new functionality to this package, consider:
16+
1. Will this code be used by both Elasticsearch and OpenSearch implementations?
17+
2. Is the functionality stable and unlikely to diverge between implementations?
18+
3. Is the function well-documented with clear input/output contracts?
19+
20+
Function Naming Conventions:
21+
- Function names should be descriptive and indicate their purpose
22+
- Parameter names should be consistent across similar functions
23+
"""
24+
25+
from .client import EsAsyncBaseFiltersClient
26+
27+
# Re-export the main functions and classes for backward compatibility
28+
from .cql2 import _replace_like_patterns, cql2_like_to_es
29+
from .transform import to_es, to_es_field
30+
31+
__all__ = [
32+
"cql2_like_to_es",
33+
"_replace_like_patterns",
34+
"to_es_field",
35+
"to_es",
36+
"EsAsyncBaseFiltersClient",
37+
]

0 commit comments

Comments
 (0)