<commit_before># views.py

from django.shortcuts import render

from wagtail.core.models import Page
from wagtail.search.models import Query


def search(request):
    # Search
    search_query = request.GET.get("q", None)
    if search_query:
        search_results = Page.objects.live().search(search_query)

        # Log the query so Wagtail can suggest promoted results
        Query.get(search_query).add_hit()
    else:
        search_results = Page.objects.none()

    # Render template
    return render(
        request,
        "core/search_results.html",
        {
            "search_query": search_query,
            "search_results": search_results,
        },
    )
<commit_msg>Add pagination to the reinstated search view<commit_after># views.py

from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator
from django.shortcuts import render

from wagtail.core.models import Page
from wagtail.search.models import Query


def search(request):
    # Search
    search_query = request.GET.get("q", None)
    page = request.GET.get("page", 1)

    if search_query:
        search_results = Page.objects.live().search(search_query)

        # Log the query so Wagtail can suggest promoted results
        Query.get(search_query).add_hit()
    else:
        search_results = Page.objects.none()

    # Pagination
    paginator = Paginator(search_results, 10)
    try:
        search_results = paginator.page(page)
    except PageNotAnInteger:
        search_results = paginator.page(1)
    except EmptyPage:
        search_results = paginator.page(paginator.num_pages)

    # Render template
    return render(
        request,
        "core/search_results.html",
        {
            "search_query": search_query,
            "search_results": search_results,
        },
    )

{'fraction_non_alphanumeric': 0.08919667590027701, 'fraction_numerical': 0.00221606648199446, 'mean_word_length': 2.7237113402061857, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '291706', 'n_tokens_mistral': 536, 'n_tokens_neox': 518, 'n_words': 124}