File tree Expand file tree Collapse file tree 3 files changed +19
-19
lines changed
stac_fastapi/elasticsearch
stac_fastapi/elasticsearch Expand file tree Collapse file tree 3 files changed +19
-19
lines changed Original file line number Diff line number Diff line change 1919 TokenPaginationExtension ,
2020 TransactionExtension ,
2121)
22-
2322from stac_fastapi .extensions .third_party import BulkTransactionExtension
2423
2524settings = ElasticsearchSettings ()
2625session = Session .create_from_settings (settings )
2726
2827filter_extension = FilterExtension (client = EsAsyncBaseFiltersClient ())
29- filter_extension .conformance_classes .append ("http://www.opengis.net/spec/cql2/1.0/req/advanced-comparison-operators" )
28+ filter_extension .conformance_classes .append (
29+ "http://www.opengis.net/spec/cql2/1.0/req/advanced-comparison-operators"
30+ )
3031
3132extensions = [
3233 TransactionExtension (client = TransactionsClient (session = session ), settings = settings ),
3637 SortExtension (),
3738 TokenPaginationExtension (),
3839 ContextExtension (),
39- filter_extension
40+ filter_extension ,
4041]
4142
4243post_request_model = create_post_request_model (extensions )
Original file line number Diff line number Diff line change @@ -184,12 +184,12 @@ def to_es(self):
184184 }
185185 }
186186 elif self .op == AdvancedComparisonOp .like :
187- return {
188- "wildcard" : {
189- to_es (self .args [0 ]): {
190- "value" : cql2_like_to_es (str (to_es (self .args [1 ]))),
187+ return {
188+ "wildcard" : {
189+ to_es (self .args [0 ]): {
190+ "value" : cql2_like_to_es (str (to_es (self .args [1 ]))),
191191 "boost" : 1.0 ,
192- "case_insensitive" : "true"
192+ "case_insensitive" : "true" ,
193193 }
194194 }
195195 }
@@ -232,23 +232,20 @@ def to_es(arg: Arg):
232232 return arg
233233 else :
234234 raise RuntimeError (f"unknown arg { repr (arg )} " )
235-
235+
236236
237237def cql2_like_to_es (input_string ):
238- """
239- Convert arugument in CQL2 ('_' and '%') to Elasticsearch wildcard operators ('?' and '*', respectively). Handle escape characters and
240- handle Elasticsearch wildcards directly.
241- """
238+ """Convert arugument in CQL2 ('_' and '%') to Elasticsearch wildcard operators ('?' and '*', respectively). Handle escape characters and handle Elasticsearch wildcards directly."""
242239 es_string = ""
243240 escape = False
244241
245242 for char in input_string :
246243 if char == "\\ " :
247244 escape = True
248- elif char == '_' and not escape :
249- es_string += '?'
250- elif char == '%' and not escape :
251- es_string += '*'
245+ elif char == "_" and not escape :
246+ es_string += "?"
247+ elif char == "%" and not escape :
248+ es_string += "*"
252249 else :
253250 es_string += char
254251 escape = False
Original file line number Diff line number Diff line change @@ -285,7 +285,9 @@ async def test_search_filter_extension_wildcard_es(app_client, ctx):
285285
286286@pytest .mark .asyncio
287287async def test_search_filter_extension_escape_chars (app_client , ctx ):
288- esc_chars = ctx .item ["properties" ]["landsat:product_id" ].replace ("_" , "\_" )[:- 1 ] + "_"
288+ esc_chars = (
289+ ctx .item ["properties" ]["landsat:product_id" ].replace ("_" , "\\ _" )[:- 1 ] + "_"
290+ )
289291
290292 params = {
291293 "filter" : {
@@ -298,7 +300,7 @@ async def test_search_filter_extension_escape_chars(app_client, ctx):
298300 {"property" : "properties.landsat:product_id" },
299301 esc_chars ,
300302 ],
301- }
303+ },
302304 ],
303305 }
304306 }
You can’t perform that action at this time.
0 commit comments