Skip to content

Instantly share code, notes, and snippets.

@groovecoder
Created May 14, 2013 19:43
Show Gist options
  • Save groovecoder/5578872 to your computer and use it in GitHub Desktop.
Save groovecoder/5578872 to your computer and use it in GitHub Desktop.
results = DocumentType.search()
if search_query:
results = (results.query(or_={'title': search_query,
'content': search_query})
.highlight('content'))
result_count = results.count()
results = results[start:end]
for doc in results:
for match in doc._highlight['content']:
match = bleach.clean(match, tags=['em',], strip=True)
return render(request, 'search/results.html', {'results': results,
'search_query': search_query,
'result_count': result_count,
'prev_page': page - 1 if start > 0 else None,
'next_page': page + 1 if end < result_count else None})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment