mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 04:02:35 +03:00
Use generator to build search conditions to reduce iterations
This commit is contained in:
parent
1ce85d01b5
commit
a7bafb7392
|
@ -158,13 +158,13 @@ class SearchFilter(BaseFilterBackend):
|
|||
]
|
||||
|
||||
base = queryset
|
||||
conditions = []
|
||||
for term in search_smart_split(search_terms):
|
||||
queries = [
|
||||
models.Q(**{orm_lookup: term})
|
||||
for orm_lookup in orm_lookups
|
||||
]
|
||||
conditions.append(reduce(operator.or_, queries))
|
||||
# generator which for each term builds the corresponding search
|
||||
conditions = (
|
||||
reduce(
|
||||
operator.or_,
|
||||
(models.Q(**{orm_lookup: term}) for orm_lookup in orm_lookups)
|
||||
) for term in search_smart_split(search_terms)
|
||||
)
|
||||
queryset = queryset.filter(reduce(operator.and_, conditions))
|
||||
|
||||
# Remove duplicates from results, if necessary
|
||||
|
|
Loading…
Reference in New Issue
Block a user