mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-20 15:17:06 +00:00
Json serialize search results
This commit is contained in:
parent
7454fb7454
commit
d990a5effd
2 changed files with 19 additions and 6 deletions
|
@ -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():
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue