You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
965 B
32 lines
965 B
from django.shortcuts import render
|
|
from django.views.decorators.http import require_GET
|
|
|
|
from .models import PageProxy
|
|
from .paginator import pagination
|
|
|
|
|
|
@require_GET
|
|
def search(request):
|
|
query = (u'%s' % request.GET.get('q', '')).strip()
|
|
|
|
if query:
|
|
results = PageProxy.indexer.search(query).prefetch().spell_correction()
|
|
|
|
# last chance to filter out unpubliched/draft pages. also accept only pages of level > 0
|
|
final_results = [
|
|
p for p in results
|
|
if p.instance.published and not p.instance.publisher_is_draft and p.instance.level > 0
|
|
]
|
|
|
|
paginator, page_obj, getvars = pagination(request, final_results)
|
|
|
|
context = dict(
|
|
maybe = results.get_corrected_query_string(),
|
|
paginator = paginator,
|
|
page_obj = page_obj,
|
|
getvars = getvars,
|
|
)
|
|
else:
|
|
context = {}
|
|
|
|
return render(request, 'search/search.html', context)
|
|
|