We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
wagtailsearch.views.frontend needs updating to use non-deprecated search method
Currently using Page.search, which is deprecated in Wagtail 1.2 - should be updated to use the QuerySet-based mechanism instead.

https://github.com/torchbox/wagtail/blob/master/wagtail/wagtailsearch/views/frontend.py#L41


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `wagtail/wagtailsearch/views/frontend.py`
Content:
```
1 from django.conf import settings
2 from django.shortcuts import render
3 from django.http import JsonResponse
4 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
5 
6 from wagtail.wagtailcore import models
7 from wagtail.wagtailsearch.models import Query
8 
9 
10 def search(
11         request,
12         template=None,
13         template_ajax=None,
14         results_per_page=10,
15         use_json=False,
16         json_attrs=['title', 'url'],
17         show_unpublished=False,
18         search_title_only=False,
19         extra_filters={},
20         path=None):
21 
22     # Get default templates
23     if template is None:
24         if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE'):
25             template = settings.WAGTAILSEARCH_RESULTS_TEMPLATE
26         else:
27             template = 'wagtailsearch/search_results.html'
28 
29     if template_ajax is None:
30         if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX'):
31             template_ajax = settings.WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX
32         else:
33             template_ajax = template
34 
35     # Get query string and page from GET paramters
36     query_string = request.GET.get('q', '')
37     page = request.GET.get('page', request.GET.get('p', 1))
38 
39     # Search
40     if query_string != '':
41         search_results = models.Page.search(
42             query_string,
43             show_unpublished=show_unpublished,
44             search_title_only=search_title_only,
45             extra_filters=extra_filters,
46             path=path if path else request.site.root_page.path
47         )
48 
49         # Get query object
50         query = Query.get(query_string)
51 
52         # Add hit
53         query.add_hit()
54 
55         # Pagination
56         paginator = Paginator(search_results, results_per_page)
57         try:
58             search_results = paginator.page(page)
59         except PageNotAnInteger:
60             search_results = paginator.page(1)
61         except EmptyPage:
62             search_results = paginator.page(paginator.num_pages)
63     else:
64         query = None
65         search_results = None
66 
67     if use_json:
68         # Return a json response
69         if search_results:
70             search_results_json = []
71             for result in search_results:
72                 result_specific = result.specific
73 
74                 search_results_json.append(dict(
75                     (attr, getattr(result_specific, attr))
76                     for attr in json_attrs
77                     if hasattr(result_specific, attr)
78                 ))
79 
80             return JsonResponse(search_results_json, safe=False)
81         else:
82             return JsonResponse([], safe=False)
83     else: # Render a template
84         if request.is_ajax() and template_ajax:
85             template = template_ajax
86 
87         return render(request, template, dict(
88             query_string=query_string,
89             search_results=search_results,
90             is_ajax=request.is_ajax(),
91             query=query
92         ))
93
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/wagtail/wagtailsearch/views/frontend.py b/wagtail/wagtailsearch/views/frontend.py
--- a/wagtail/wagtailsearch/views/frontend.py
+++ b/wagtail/wagtailsearch/views/frontend.py
@@ -38,13 +38,18 @@
 
     # Search
     if query_string != '':
-        search_results = models.Page.search(
-            query_string,
-            show_unpublished=show_unpublished,
-            search_title_only=search_title_only,
-            extra_filters=extra_filters,
-            path=path if path else request.site.root_page.path
-        )
+        pages = models.Page.objects.filter(path__startswith=(path or request.site.root_page.path))
+
+        if not show_unpublished:
+            pages = pages.live()
+
+        if extra_filters:
+            pages = pages.filter(**extra_filters)
+
+        if search_title_only:
+            search_results = pages.search(query_string, fields=['title'])
+        else:
+            search_results = pages.search(query_string)
 
         # Get query object
         query = Query.get(query_string)

{"golden_diff": "diff --git a/wagtail/wagtailsearch/views/frontend.py b/wagtail/wagtailsearch/views/frontend.py\n--- a/wagtail/wagtailsearch/views/frontend.py\n+++ b/wagtail/wagtailsearch/views/frontend.py\n@@ -38,13 +38,18 @@\n \n     # Search\n     if query_string != '':\n-        search_results = models.Page.search(\n-            query_string,\n-            show_unpublished=show_unpublished,\n-            search_title_only=search_title_only,\n-            extra_filters=extra_filters,\n-            path=path if path else request.site.root_page.path\n-        )\n+        pages = models.Page.objects.filter(path__startswith=(path or request.site.root_page.path))\n+\n+        if not show_unpublished:\n+            pages = pages.live()\n+\n+        if extra_filters:\n+            pages = pages.filter(**extra_filters)\n+\n+        if search_title_only:\n+            search_results = pages.search(query_string, fields=['title'])\n+        else:\n+            search_results = pages.search(query_string)\n \n         # Get query object\n         query = Query.get(query_string)\n", "issue": "wagtailsearch.views.frontend needs updating to use non-deprecated search method\nCurrently using Page.search, which is deprecated in Wagtail 1.2 - should be updated to use the QuerySet-based mechanism instead.\n\nhttps://github.com/torchbox/wagtail/blob/master/wagtail/wagtailsearch/views/frontend.py#L41\n\n", "before_files": [{"content": "from django.conf import settings\nfrom django.shortcuts import render\nfrom django.http import JsonResponse\nfrom django.core.paginator import Paginator, EmptyPage, PageNotAnInteger\n\nfrom wagtail.wagtailcore import models\nfrom wagtail.wagtailsearch.models import Query\n\n\ndef search(\n        request,\n        template=None,\n        template_ajax=None,\n        results_per_page=10,\n        use_json=False,\n        json_attrs=['title', 'url'],\n        show_unpublished=False,\n        search_title_only=False,\n        extra_filters={},\n        path=None):\n\n    # Get default templates\n    if template is None:\n        if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE'):\n            template = settings.WAGTAILSEARCH_RESULTS_TEMPLATE\n        else:\n            template = 'wagtailsearch/search_results.html'\n\n    if template_ajax is None:\n        if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX'):\n            template_ajax = settings.WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX\n        else:\n            template_ajax = template\n\n    # Get query string and page from GET paramters\n    query_string = request.GET.get('q', '')\n    page = request.GET.get('page', request.GET.get('p', 1))\n\n    # Search\n    if query_string != '':\n        search_results = models.Page.search(\n            query_string,\n            show_unpublished=show_unpublished,\n            search_title_only=search_title_only,\n            extra_filters=extra_filters,\n            path=path if path else request.site.root_page.path\n        )\n\n        # Get query object\n        query = Query.get(query_string)\n\n        # Add hit\n        query.add_hit()\n\n        # Pagination\n        paginator = Paginator(search_results, results_per_page)\n        try:\n            search_results = paginator.page(page)\n        except PageNotAnInteger:\n            search_results = paginator.page(1)\n        except EmptyPage:\n            search_results = paginator.page(paginator.num_pages)\n    else:\n        query = None\n        search_results = None\n\n    if use_json:\n        # Return a json response\n        if search_results:\n            search_results_json = []\n            for result in search_results:\n                result_specific = result.specific\n\n                search_results_json.append(dict(\n                    (attr, getattr(result_specific, attr))\n                    for attr in json_attrs\n                    if hasattr(result_specific, attr)\n                ))\n\n            return JsonResponse(search_results_json, safe=False)\n        else:\n            return JsonResponse([], safe=False)\n    else: # Render a template\n        if request.is_ajax() and template_ajax:\n            template = template_ajax\n\n        return render(request, template, dict(\n            query_string=query_string,\n            search_results=search_results,\n            is_ajax=request.is_ajax(),\n            query=query\n        ))\n", "path": "wagtail/wagtailsearch/views/frontend.py"}], "after_files": [{"content": "from django.conf import settings\nfrom django.shortcuts import render\nfrom django.http import JsonResponse\nfrom django.core.paginator import Paginator, EmptyPage, PageNotAnInteger\n\nfrom wagtail.wagtailcore import models\nfrom wagtail.wagtailsearch.models import Query\n\n\ndef search(\n        request,\n        template=None,\n        template_ajax=None,\n        results_per_page=10,\n        use_json=False,\n        json_attrs=['title', 'url'],\n        show_unpublished=False,\n        search_title_only=False,\n        extra_filters={},\n        path=None):\n\n    # Get default templates\n    if template is None:\n        if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE'):\n            template = settings.WAGTAILSEARCH_RESULTS_TEMPLATE\n        else:\n            template = 'wagtailsearch/search_results.html'\n\n    if template_ajax is None:\n        if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX'):\n            template_ajax = settings.WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX\n        else:\n            template_ajax = template\n\n    # Get query string and page from GET paramters\n    query_string = request.GET.get('q', '')\n    page = request.GET.get('page', request.GET.get('p', 1))\n\n    # Search\n    if query_string != '':\n        pages = models.Page.objects.filter(path__startswith=(path or request.site.root_page.path))\n\n        if not show_unpublished:\n            pages = pages.live()\n\n        if extra_filters:\n            pages = pages.filter(**extra_filters)\n\n        if search_title_only:\n            search_results = pages.search(query_string, fields=['title'])\n        else:\n            search_results = pages.search(query_string)\n\n        # Get query object\n        query = Query.get(query_string)\n\n        # Add hit\n        query.add_hit()\n\n        # Pagination\n        paginator = Paginator(search_results, results_per_page)\n        try:\n            search_results = paginator.page(page)\n        except PageNotAnInteger:\n            search_results = paginator.page(1)\n        except EmptyPage:\n            search_results = paginator.page(paginator.num_pages)\n    else:\n        query = None\n        search_results = None\n\n    if use_json:\n        # Return a json response\n        if search_results:\n            search_results_json = []\n            for result in search_results:\n                result_specific = result.specific\n\n                search_results_json.append(dict(\n                    (attr, getattr(result_specific, attr))\n                    for attr in json_attrs\n                    if hasattr(result_specific, attr)\n                ))\n\n            return JsonResponse(search_results_json, safe=False)\n        else:\n            return JsonResponse([], safe=False)\n    else: # Render a template\n        if request.is_ajax() and template_ajax:\n            template = template_ajax\n\n        return render(request, template, dict(\n            query_string=query_string,\n            search_results=search_results,\n            is_ajax=request.is_ajax(),\n            query=query\n        ))\n", "path": "wagtail/wagtailsearch/views/frontend.py"}]}