fix searching by url contents

This commit is contained in:
Nick Sweeting 2021-04-05 23:21:07 -04:00
parent 2fc9f1cfa3
commit cadac4838e
2 changed files with 9 additions and 12 deletions

View file

@ -2,22 +2,19 @@ from django.contrib import messages
from archivebox.search import query_search_index from archivebox.search import query_search_index
class SearchResultsAdminMixin(object): class SearchResultsAdminMixin:
def get_search_results(self, request, queryset, search_term): def get_search_results(self, request, queryset, search_term: str):
''' Enhances the search queryset with results from the search backend. """Enhances the search queryset with results from the search backend"""
'''
qs, use_distinct = \ qs, use_distinct = super().get_search_results(request, queryset, search_term)
super(SearchResultsAdminMixin, self).get_search_results(
request, queryset, search_term)
search_term = search_term.strip() search_term = search_term.strip()
if not search_term: if not search_term:
return qs, use_distinct return qs, use_distinct
try: try:
qsearch = query_search_index(search_term) qsearch = query_search_index(search_term)
qs = qs | qsearch
except Exception as err: except Exception as err:
messages.add_message(request, messages.WARNING, f'Error from the search backend, only showing results from default admin search fields - Error: {err}') messages.add_message(request, messages.WARNING, f'Error from the search backend, only showing results from default admin search fields - Error: {err}')
else:
qs = queryset & qsearch return qs, use_distinct
finally:
return qs, use_distinct