@@ -159,7 +159,6 @@ def _visit_term(
159
159
raise ValueError (f"No handler for term type { type (term ).__name__ } " )
160
160
return handler (term , context )
161
161
162
- # AST-style handlers for term types
163
162
@classmethod
164
163
def handle_term_Filter (
165
164
cls , term : Filter , context : SearchContext
@@ -179,7 +178,6 @@ def handle_term_Filter(
179
178
def handle_term_And (
180
179
cls , term : And , context : SearchContext
181
180
) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
182
- """Handle AND logic between terms."""
183
181
lhs_sql , lhs_params , lhs_context = cls ._visit_term (term .lhs , context )
184
182
rhs_sql , rhs_params , rhs_context = cls ._visit_term (term .rhs , context )
185
183
@@ -190,7 +188,6 @@ def handle_term_And(
190
188
def handle_term_Or (
191
189
cls , term : Or , context : SearchContext
192
190
) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
193
- """Handle OR logic between terms."""
194
191
lhs_sql , lhs_params , lhs_context = cls ._visit_term (term .lhs , context )
195
192
rhs_sql , rhs_params , rhs_context = cls ._visit_term (term .rhs , context )
196
193
@@ -201,15 +198,13 @@ def handle_term_Or(
201
198
def handle_term_Not (
202
199
cls , term : Not , context : SearchContext
203
200
) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
204
- """Handle NOT logic."""
205
201
inner_sql , inner_params , _ = cls ._visit_term (term .term , context )
206
202
return f"(NOT { inner_sql } )" , inner_params , context
207
203
208
204
@classmethod
209
205
def handle_filter_name (
210
206
cls , term : Filter , context : SearchContext
211
207
) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
212
- """Handle name filtering."""
213
208
if term .value .startswith ('"' ):
214
209
# Exact quoted match
215
210
value = term .value [1 :- 1 ]
@@ -233,7 +228,6 @@ def handle_filter_name(
233
228
def handle_filter_summary (
234
229
cls , term : Filter , context : SearchContext
235
230
) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
236
- """Handle summary filtering."""
237
231
if term .value .startswith ('"' ):
238
232
value = term .value [1 :- 1 ]
239
233
else :
@@ -257,13 +251,7 @@ def handle_filter_name_or_summary(
257
251
def _build_ordering_from_context (
258
252
cls , context : SearchContext
259
253
) -> tuple [str , tuple [typing .Any , ...]]:
260
- """Build mixed ordering for exact names and fuzzy patterns.
261
-
262
- For "scipy or scikit-*", the ordering is:
263
- 1. Exact matches get closeness-based priority (scipy, scipy2, etc.)
264
- 2. Fuzzy matches get length-based priority (scikit-learn, scikit-image, etc.)
265
- 3. Everything else alphabetical
266
- """
254
+ """Build mixed ordering for exact names and fuzzy patterns."""
267
255
268
256
exact_names , fuzzy_patterns = context .exact_names , context .fuzzy_patterns
269
257
order_parts = []
@@ -289,9 +277,10 @@ def _build_ordering_from_context(
289
277
all_params .extend ([f"{ name } %" , f"%{ name } " ])
290
278
291
279
if case_conditions :
280
+ cond = "\n " .join (case_conditions )
292
281
priority_expr = f"""
293
282
CASE
294
- { chr ( 10 ). join ( case_conditions ) }
283
+ { cond }
295
284
ELSE 3
296
285
END
297
286
"""
0 commit comments