From 8c8584922ed16eb326e13228fb56f4bbfcdc3ef6 Mon Sep 17 00:00:00 2001 From: Kaitlyn Crawford Date: Thu, 25 Feb 2016 14:02:52 +0200 Subject: [PATCH] removed restriction to only search on title field --- .../wagtailadmin/tests/test_pages_views.py | 28 +++++++++++++++++++ wagtail/wagtailadmin/views/pages.py | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 78a1f6effe..b259b17a56 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -20,6 +20,7 @@ from wagtail.tests.utils import WagtailTestUtils from wagtail.wagtailcore.models import GroupPagePermission, Page, PageRevision, Site from wagtail.wagtailcore.signals import page_published, page_unpublished from wagtail.wagtailusers.models import UserProfile +from wagtail.wagtailsearch.index import SearchField def submittable_timestamp(timestamp): @@ -1477,6 +1478,33 @@ class TestPageSearch(TestCase, WagtailTestUtils): self.assertTemplateUsed(response, 'wagtailadmin/pages/search.html') self.assertEqual(response.context['query_string'], "Hello") + def test_search_searchable_fields(self): + # Find root page + root_page = Page.objects.get(id=2) + + # Create a page + root_page.add_child(instance=SimplePage( + title="Hi there!", + slug='hello-world', + live=True, + has_unpublished_changes=False, + )) + + # Confirm the slug is not being searched + response = self.get({'q': "hello"}) + self.assertNotContains(response, "There is one matching page") + search_fields = Page.search_fields + + # Add slug to the search_fields + Page.search_fields = Page.search_fields + (SearchField('slug', partial_match=True),) + + # Confirm the slug is being searched + response = self.get({'q': "hello"}) + self.assertContains(response, "There is one matching page") + + # Reset the search fields + Page.search_fields = search_fields + def test_ajax(self): response = self.get({'q': "Hello"}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertEqual(response.status_code, 200) diff --git a/wagtail/wagtailadmin/views/pages.py b/wagtail/wagtailadmin/views/pages.py index 3c2a6e6b22..88e295a8cb 100644 --- a/wagtail/wagtailadmin/views/pages.py +++ b/wagtail/wagtailadmin/views/pages.py @@ -680,7 +680,7 @@ def search(request): if form.is_valid(): q = form.cleaned_data['q'] - pages = Page.objects.all().prefetch_related('content_type').search(q, fields=['title']) + pages = Page.objects.all().prefetch_related('content_type').search(q) paginator, pages = paginate(request, pages) else: form = SearchForm()