@@ -159,7 +159,6 @@ def _visit_term(
159159 raise ValueError (f"No handler for term type { type (term ).__name__ } " )
160160 return handler (term , context )
161161
162- # AST-style handlers for term types
163162 @classmethod
164163 def handle_term_Filter (
165164 cls , term : Filter , context : SearchContext
@@ -179,7 +178,6 @@ def handle_term_Filter(
179178 def handle_term_And (
180179 cls , term : And , context : SearchContext
181180 ) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
182- """Handle AND logic between terms."""
183181 lhs_sql , lhs_params , lhs_context = cls ._visit_term (term .lhs , context )
184182 rhs_sql , rhs_params , rhs_context = cls ._visit_term (term .rhs , context )
185183
@@ -190,7 +188,6 @@ def handle_term_And(
190188 def handle_term_Or (
191189 cls , term : Or , context : SearchContext
192190 ) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
193- """Handle OR logic between terms."""
194191 lhs_sql , lhs_params , lhs_context = cls ._visit_term (term .lhs , context )
195192 rhs_sql , rhs_params , rhs_context = cls ._visit_term (term .rhs , context )
196193
@@ -201,15 +198,13 @@ def handle_term_Or(
201198 def handle_term_Not (
202199 cls , term : Not , context : SearchContext
203200 ) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
204- """Handle NOT logic."""
205201 inner_sql , inner_params , _ = cls ._visit_term (term .term , context )
206202 return f"(NOT { inner_sql } )" , inner_params , context
207203
208204 @classmethod
209205 def handle_filter_name (
210206 cls , term : Filter , context : SearchContext
211207 ) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
212- """Handle name filtering."""
213208 if term .value .startswith ('"' ):
214209 # Exact quoted match
215210 value = term .value [1 :- 1 ]
@@ -233,7 +228,6 @@ def handle_filter_name(
233228 def handle_filter_summary (
234229 cls , term : Filter , context : SearchContext
235230 ) -> tuple [str , tuple [typing .Any , ...], SearchContext ]:
236- """Handle summary filtering."""
237231 if term .value .startswith ('"' ):
238232 value = term .value [1 :- 1 ]
239233 else :
@@ -257,13 +251,7 @@ def handle_filter_name_or_summary(
257251 def _build_ordering_from_context (
258252 cls , context : SearchContext
259253 ) -> 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."""
267255
268256 exact_names , fuzzy_patterns = context .exact_names , context .fuzzy_patterns
269257 order_parts = []
@@ -289,9 +277,10 @@ def _build_ordering_from_context(
289277 all_params .extend ([f"{ name } %" , f"%{ name } " ])
290278
291279 if case_conditions :
280+ cond = "\n " .join (case_conditions )
292281 priority_expr = f"""
293282 CASE
294- { chr ( 10 ). join ( case_conditions ) }
283+ { cond }
295284 ELSE 3
296285 END
297286 """
0 commit comments