@@ -24,15 +24,19 @@ def search_smart_split(search_terms):
24
24
"""generator that first splits string by spaces, leaving quoted phrases together,
25
25
then it splits non-quoted phrases by commas.
26
26
"""
27
+ split_terms = []
27
28
for term in smart_split (search_terms ):
28
29
# trim commas to avoid bad matching for quoted phrases
29
30
term = term .strip (',' )
30
31
if term .startswith (('"' , "'" )) and term [0 ] == term [- 1 ]:
31
32
# quoted phrases are kept together without any other split
32
- yield unescape_string_literal (term )
33
+ split_terms . append ( unescape_string_literal (term ) )
33
34
else :
34
35
# non-quoted tokens are split by comma, keeping only non-empty ones
35
- yield from (sub_term .strip () for sub_term in term .split (',' ) if sub_term )
36
+ for sub_term in term .split (',' ):
37
+ if sub_term :
38
+ split_terms .append (sub_term .strip ())
39
+ return split_terms
36
40
37
41
38
42
class BaseFilterBackend :
@@ -85,7 +89,8 @@ def get_search_terms(self, request):
85
89
"""
86
90
value = request .query_params .get (self .search_param , '' )
87
91
field = CharField (trim_whitespace = False , allow_blank = True )
88
- return field .run_validation (value )
92
+ cleaned_value = field .run_validation (value )
93
+ return search_smart_split (cleaned_value )
89
94
90
95
def construct_search (self , field_name , queryset ):
91
96
lookup = self .lookup_prefixes .get (field_name [0 ])
@@ -163,7 +168,7 @@ def filter_queryset(self, request, queryset, view):
163
168
reduce (
164
169
operator .or_ ,
165
170
(models .Q (** {orm_lookup : term }) for orm_lookup in orm_lookups )
166
- ) for term in search_smart_split ( search_terms )
171
+ ) for term in search_terms
167
172
)
168
173
queryset = queryset .filter (reduce (operator .and_ , conditions ))
169
174
0 commit comments