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 19
19
TokenPaginationExtension ,
20
20
TransactionExtension ,
21
21
)
22
-
23
22
from stac_fastapi .extensions .third_party import BulkTransactionExtension
24
23
25
24
settings = ElasticsearchSettings ()
26
25
session = Session .create_from_settings (settings )
27
26
28
27
filter_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
+ )
30
31
31
32
extensions = [
32
33
TransactionExtension (client = TransactionsClient (session = session ), settings = settings ),
36
37
SortExtension (),
37
38
TokenPaginationExtension (),
38
39
ContextExtension (),
39
- filter_extension
40
+ filter_extension ,
40
41
]
41
42
42
43
post_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):
184
184
}
185
185
}
186
186
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 ]))),
191
191
"boost" : 1.0 ,
192
- "case_insensitive" : "true"
192
+ "case_insensitive" : "true" ,
193
193
}
194
194
}
195
195
}
@@ -232,23 +232,20 @@ def to_es(arg: Arg):
232
232
return arg
233
233
else :
234
234
raise RuntimeError (f"unknown arg { repr (arg )} " )
235
-
235
+
236
236
237
237
def 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."""
242
239
es_string = ""
243
240
escape = False
244
241
245
242
for char in input_string :
246
243
if char == "\\ " :
247
244
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 += "*"
252
249
else :
253
250
es_string += char
254
251
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):
285
285
286
286
@pytest .mark .asyncio
287
287
async 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
+ )
289
291
290
292
params = {
291
293
"filter" : {
@@ -298,7 +300,7 @@ async def test_search_filter_extension_escape_chars(app_client, ctx):
298
300
{"property" : "properties.landsat:product_id" },
299
301
esc_chars ,
300
302
],
301
- }
303
+ },
302
304
],
303
305
}
304
306
}
You can’t perform that action at this time.
0 commit comments