prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Paginator and search pagination expect different parameters for page
  The Paginator (as in `django.core.paginator`) used pretty much everywhere uses `page` as the query parameter. The search view, however, [expects](https://github.com/torchbox/wagtail/blob/100797796df0bc8ca96035092f32a9275d2b3713/wagtail/wagtailsearch/views/queries.py#L28) a `p` query parameter for pagination.
  
  While not a bug, it is a bit confusing and makes it less elegant to share a pagination include. Certainly made me scratch my head.
  
  Worth a PR?
  
  Cheers,
  Dan
  
  
  --- 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 import json
  2 
  3 from django.conf import settings
  4 from django.shortcuts import render
  5 from django.http import HttpResponse
  6 from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
  7 
  8 from wagtail.wagtailcore import models
  9 from wagtail.wagtailsearch.models import Query
  10 
  11 
  12 def search(
  13         request,
  14         template=None,
  15         template_ajax=None,
  16         results_per_page=10,
  17         use_json=False,
  18         json_attrs=['title', 'url'],
  19         show_unpublished=False,
  20         search_title_only=False,
  21         extra_filters={},
  22         path=None,
  23     ):
  24 
  25     # Get default templates
  26     if template is None:
  27         if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE'):
  28             template = settings.WAGTAILSEARCH_RESULTS_TEMPLATE
  29         else:
  30             template = 'wagtailsearch/search_results.html'
  31 
  32     if template_ajax is None:
  33         if hasattr(settings, 'WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX'):
  34             template_ajax = settings.WAGTAILSEARCH_RESULTS_TEMPLATE_AJAX
  35         else:
  36             template_ajax = template
  37 
  38     # Get query string and page from GET paramters
  39     query_string = request.GET.get('q', '')
  40     page = request.GET.get('p', 1)
  41 
  42     # Search
  43     if query_string != '':
  44         search_results = models.Page.search(
  45             query_string,
  46             show_unpublished=show_unpublished,
  47             search_title_only=search_title_only,
  48             extra_filters=extra_filters,
  49             path=path if path else request.site.root_page.path
  50         )
  51 
  52         # Get query object
  53         query = Query.get(query_string)
  54 
  55         # Add hit
  56         query.add_hit()
  57 
  58         # Pagination
  59         paginator = Paginator(search_results, results_per_page)
  60         try:
  61             search_results = paginator.page(page)
  62         except PageNotAnInteger:
  63             search_results = paginator.page(1)
  64         except EmptyPage:
  65             search_results = paginator.page(paginator.num_pages)
  66     else:
  67         query = None
  68         search_results = None
  69 
  70     if use_json: # Return a json response
  71         if search_results:
  72             search_results_json = []
  73             for result in search_results:
  74                 result_specific = result.specific
  75 
  76                 search_results_json.append(dict(
  77                     (attr, getattr(result_specific, attr))
  78                     for attr in json_attrs
  79                     if hasattr(result_specific, attr)
  80                 ))
  81 
  82             return HttpResponse(json.dumps(search_results_json))
  83         else:
  84             return HttpResponse('[]')
  85     else: # Render a template
  86         if request.is_ajax() and template_ajax:
  87             template = template_ajax
  88 
  89         return render(request, template, dict(
  90             query_string=query_string,
  91             search_results=search_results,
  92             is_ajax=request.is_ajax(),
  93             query=query
  94         ))
  95
  ```
  --- 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()
  
  ```
  
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
  @@ -37,7 +37,7 @@
   
       # Get query string and page from GET paramters
       query_string = request.GET.get('q', '')
  -    page = request.GET.get('p', 1)
  +    page = request.GET.get('page', request.GET.get('p', 1))
   
       # Search
       if 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@@ -37,7 +37,7 @@\n \n     # Get query string and page from GET paramters\n     query_string = request.GET.get('q', '')\n-    page = request.GET.get('p', 1)\n+    page = request.GET.get('page', request.GET.get('p', 1))\n \n     # Search\n     if query_string != '':\n", "issue": "Paginator and search pagination expect different parameters for page\nThe Paginator (as in `django.core.paginator`) used pretty much everywhere uses `page` as the query parameter. The search view, however, [expects](https://github.com/torchbox/wagtail/blob/100797796df0bc8ca96035092f32a9275d2b3713/wagtail/wagtailsearch/views/queries.py#L28) a `p` query parameter for pagination.\n\nWhile not a bug, it is a bit confusing and makes it less elegant to share a pagination include. Certainly made me scratch my head.\n\nWorth a PR?\n\nCheers,\nDan\n\n", "before_files": [{"content": "import json\n\nfrom django.conf import settings\nfrom django.shortcuts import render\nfrom django.http import HttpResponse\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\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('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: # 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 HttpResponse(json.dumps(search_results_json))\n        else:\n            return HttpResponse('[]')\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": "import json\n\nfrom django.conf import settings\nfrom django.shortcuts import render\nfrom django.http import HttpResponse\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\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: # 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 HttpResponse(json.dumps(search_results_json))\n        else:\n            return HttpResponse('[]')\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"}]}