Json serialize search results

This commit is contained in:
Mouse Reeve 2020-05-04 10:15:41 -07:00
parent 7454fb7454
commit d990a5effd
2 changed files with 19 additions and 6 deletions

View file

@ -48,6 +48,13 @@ def search(query):
return results
def local_search(query):
''' only look at local search results '''
connector = load_connector(models.Connector.objects.get(local=True))
return connector.search(query)
def first_search_result(query):
''' search until you find a result that fits '''
for connector in get_connectors():

View file

@ -150,13 +150,19 @@ def search(request):
if re.match(r'\w+@\w+.\w+', query):
# if something looks like a username, search with webfinger
results = [outgoing.handle_account_search(query)]
template = 'user_results.html'
else:
# just send the question over to book search
results = books_manager.search(query)
template = 'book_results.html'
return TemplateResponse(
request, 'user_results.html', {'results': results}
)
return TemplateResponse(request, template, {'results': results})
# or just send the question over to book search
if is_api_request(request):
# only return local results via json so we don't cause a cascade
results = books_manager.local_search(query)
return JsonResponse([r.__dict__ for r in results], safe=False)
results = books_manager.search(query)
return TemplateResponse(request, 'book_results.html', {'results': results})
def books_page(request):