From 358ef76529d2f88c53ac9758151d2762d37c7d0d Mon Sep 17 00:00:00 2001 From: Aaron Tan Date: Fri, 22 Sep 2017 16:06:59 -0400 Subject: [PATCH] Remove search term separators Relates #7656 in ansible-tower. We have been using comma `,` and space ` ` to separate search terms in query string `__search=`, however in general we can always use `&` to achieve separation like `__search=&__search=&...`. Using specific delimiters makes it impossible for search terms to contain those delimiters, so they are better off being removed. Signed-off-by: Aaron Tan --- awx/api/filters.py | 9 ++++----- awx/api/templates/api/_list_common.md | 12 ++++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/awx/api/filters.py b/awx/api/filters.py index a231c8af8d..105403bd17 100644 --- a/awx/api/filters.py +++ b/awx/api/filters.py @@ -242,11 +242,10 @@ class FieldLookupBackend(BaseFilterBackend): # Search across related objects. if key.endswith('__search'): for value in values: - for search_term in force_text(value).replace(',', ' ').split(): - search_value, new_keys = self.value_to_python(queryset.model, key, search_term) - assert isinstance(new_keys, list) - for new_key in new_keys: - search_filters.append((new_key, search_value)) + search_value, new_keys = self.value_to_python(queryset.model, key, force_text(value)) + assert isinstance(new_keys, list) + for new_key in new_keys: + search_filters.append((new_key, search_value)) continue # Custom chain__ and or__ filters, mutually exclusive (both can diff --git a/awx/api/templates/api/_list_common.md b/awx/api/templates/api/_list_common.md index 706ae732a5..de58292756 100644 --- a/awx/api/templates/api/_list_common.md +++ b/awx/api/templates/api/_list_common.md @@ -1,9 +1,9 @@ The resulting data structure contains: { - "count": 99, - "next": null, - "previous": null, + "count": 99, + "next": null, + "previous": null, "results": [ ... ] @@ -60,6 +60,10 @@ _Added in AWX 1.4_ ?related__search=findme +Note: If you want to provide more than one search terms, please use multiple +search fields with the same key, like `?related__search=foo&related__search=bar`, +All search terms with the same key will be ORed together. + ## Filtering Any additional query string parameters may be used to filter the list of @@ -70,7 +74,7 @@ in the specified value should be url-encoded. For example: ?field=value%20xyz Fields may also span relations, only for fields and relationships defined in -the database: +the database: ?other__field=value