mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-11 16:53:10 +00:00
removed restriction to only search on title field
This commit is contained in:
parent
6bae4f04ca
commit
8c8584922e
2 changed files with 29 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue