@@ -266,7 +266,8 @@ async def all_collections(
266266 if field [0 ] == "-" :
267267 excludes .add (field [1 :])
268268 else :
269- includes .add (field [1 :] if field [0 ] in "+ " else field )
269+ include_field = field [1 :] if field [0 ] in "+ " else field
270+ includes .add (include_field )
270271
271272 sort = None
272273 if sortby :
@@ -314,34 +315,41 @@ async def all_collections(
314315 detail = f"Only 'cql2-json' and 'cql2-text' filter languages are supported for collections. Got '{ filter_lang } '." ,
315316 )
316317
317- # Handle different filter formats
318- try :
319- if filter_lang == "cql2-text" or filter_lang is None :
320- # For cql2-text or when no filter_lang is specified, try both formats
321- try :
322- # First try to parse as JSON
323- parsed_filter = orjson .loads (unquote_plus (filter_expr ))
324- except Exception :
325- # If that fails, use pygeofilter to convert CQL2-text to CQL2-JSON
326- try :
327- # Parse CQL2-text and convert to CQL2-JSON
328- text_filter = unquote_plus (filter_expr )
329- parsed_ast = parse_cql2_text (text_filter )
330- parsed_filter = to_cql2 (parsed_ast )
331- except Exception as e :
332- # If parsing fails, provide a helpful error message
333- raise HTTPException (
334- status_code = 400 ,
335- detail = f"Invalid CQL2-text filter: { e } . Please check your syntax." ,
336- )
337- else :
338- # For explicit cql2-json, parse as JSON
339- parsed_filter = orjson .loads (unquote_plus (filter_expr ))
340- except Exception as e :
341- # Catch any other parsing errors
342- raise HTTPException (
343- status_code = 400 , detail = f"Error parsing filter: { e } "
344- )
318+ # # Handle different filter formats
319+ # try:
320+ # if filter_lang == "cql2-text" or filter_lang is None:
321+ # # For cql2-text or when no filter_lang is specified, try both formats
322+ # try:
323+ # # First try to parse as JSON
324+ # parsed_filter = orjson.loads(unquote_plus(filter_expr))
325+ # except Exception:
326+ # # If that fails, use pygeofilter to convert CQL2-text to CQL2-JSON
327+ # try:
328+ # # Parse CQL2-text and convert to CQL2-JSON
329+ # text_filter = unquote_plus(filter_expr)
330+ # parsed_ast = parse_cql2_text(text_filter)
331+ # parsed_filter = to_cql2(parsed_ast)
332+ # except Exception as e:
333+ # # If parsing fails, provide a helpful error message
334+ # raise HTTPException(
335+ # status_code=400,
336+ # detail=f"Invalid CQL2-text filter: {e}. Please check your syntax.",
337+ # )
338+ # else:
339+ # # For explicit cql2-json, parse as JSON
340+ # parsed_filter = orjson.loads(unquote_plus(filter_expr))
341+ # except Exception as e:
342+ # # Catch any other parsing errors
343+ # raise HTTPException(
344+ # status_code=400, detail=f"Error parsing filter: {e}"
345+ # )
346+
347+ # Handle both cql2-json and cql2-text
348+ parsed_filter = orjson .loads (
349+ unquote_plus (filter_expr )
350+ if filter_lang == "cql2-json" or filter_lang is None
351+ else to_cql2 (parse_cql2_text (filter_expr ))
352+ )
345353 except Exception as e :
346354 raise HTTPException (
347355 status_code = 400 , detail = f"Invalid filter parameter: { e } "
@@ -404,31 +412,9 @@ async def post_all_collections(
404412 Returns:
405413 A Collections object containing all the collections in the database and links to various resources.
406414 """
407- # Debug print
408- print ("search_request: " , search_request )
409- # Set the postbody attribute on the request object for PagingLinks
410415 request .postbody = search_request .model_dump (exclude_unset = True )
411416
412417 fields = None
413- # Check for fields attribute (legacy format)
414- if hasattr (search_request , "fields" ) and search_request .fields :
415- fields = []
416-
417- # Handle include fields
418- if (
419- hasattr (search_request .fields , "include" )
420- and search_request .fields .include
421- ):
422- for field in search_request .fields .include :
423- fields .append (f"+{ field } " )
424-
425- # Handle exclude fields
426- if (
427- hasattr (search_request .fields , "exclude" )
428- and search_request .fields .exclude
429- ):
430- for field in search_request .fields .exclude :
431- fields .append (f"-{ field } " )
432418
433419 # Check for field attribute (ExtendedSearch format)
434420 if hasattr (search_request , "field" ) and search_request .field :
0 commit comments