mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 12:12:19 +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
|
base = queryset
|
||||||
conditions = []
|
# generator which for each term builds the corresponding search
|
||||||
for term in search_smart_split(search_terms):
|
conditions = (
|
||||||
queries = [
|
reduce(
|
||||||
models.Q(**{orm_lookup: term})
|
operator.or_,
|
||||||
for orm_lookup in orm_lookups
|
(models.Q(**{orm_lookup: term}) for orm_lookup in orm_lookups)
|
||||||
]
|
) for term in search_smart_split(search_terms)
|
||||||
conditions.append(reduce(operator.or_, queries))
|
)
|
||||||
queryset = queryset.filter(reduce(operator.and_, conditions))
|
queryset = queryset.filter(reduce(operator.and_, conditions))
|
||||||
|
|
||||||
# Remove duplicates from results, if necessary
|
# Remove duplicates from results, if necessary
|
||||||
|
|
Loading…
Reference in New Issue
Block a user