mirror of
https://github.com/ArchiveBox/ArchiveBox
synced 2024-11-26 06:00:22 +00:00
aca0512926
Making sure the search results are unique
21 lines
908 B
Python
21 lines
908 B
Python
from django.contrib import messages
|
|
|
|
from archivebox.search import query_search_index
|
|
|
|
class SearchResultsAdminMixin:
|
|
def get_search_results(self, request, queryset, search_term: str):
|
|
"""Enhances the search queryset with results from the search backend"""
|
|
|
|
qs, use_distinct = super().get_search_results(request, queryset, search_term)
|
|
|
|
search_term = search_term.strip()
|
|
if not search_term:
|
|
return qs, use_distinct
|
|
try:
|
|
qsearch = query_search_index(search_term)
|
|
qs = qs | qsearch
|
|
except Exception as err:
|
|
print(f'[!] Error while using search backend: {err.__class__.__name__} {err}')
|
|
messages.add_message(request, messages.WARNING, f'Error from the search backend, only showing results from default admin search fields - Error: {err}')
|
|
|
|
return qs.distinct(), use_distinct
|