prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <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
  
  
  </issue>
  <code>
  [start of wagtail/wagtailsearch/views/frontend.py]
  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 of wagtail/wagtailsearch/views/frontend.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: 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)
  
verification_info: {"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"}]}