diff --git a/bookwyrm/templates/search_results.html b/bookwyrm/templates/search_results.html index 2dba79a2..9188c1f0 100644 --- a/bookwyrm/templates/search_results.html +++ b/bookwyrm/templates/search_results.html @@ -70,10 +70,11 @@ {% endif %}
+ {% if request.user.is_authenticated %}

{% trans "Matching Users" %}

{% if not user_results %} -

{% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}

+

{% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}

{% endif %}
+ {% endif %}

{% trans "Lists" %}

{% if not list_results %} -

{% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}

+

{% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}

{% endif %} {% for result in list_results %}
diff --git a/bookwyrm/views/search.py b/bookwyrm/views/search.py index 4543b55e..bd5ac3c7 100644 --- a/bookwyrm/views/search.py +++ b/bookwyrm/views/search.py @@ -30,27 +30,30 @@ class Search(View): ) return JsonResponse([r.json() for r in book_results], safe=False) + data = {"query": query or ""} + # use webfinger for mastodon style account@domain.com username if query and re.match(regex.full_username, query): handle_remote_webfinger(query) # do a user search - user_results = ( - models.User.viewer_aware_objects(request.user) - .annotate( - similarity=Greatest( - TrigramSimilarity("username", query), - TrigramSimilarity("localname", query), + if request.user.is_authenticated: + data["user_results"] = ( + models.User.viewer_aware_objects(request.user) + .annotate( + similarity=Greatest( + TrigramSimilarity("username", query), + TrigramSimilarity("localname", query), + ) ) + .filter( + similarity__gt=0.5, + ) + .order_by("-similarity")[:10] ) - .filter( - similarity__gt=0.5, - ) - .order_by("-similarity")[:10] - ) # any relevent lists? - list_results = ( + data["list_results"] = ( privacy_filter( request.user, models.List.objects, @@ -68,11 +71,7 @@ class Search(View): .order_by("-similarity")[:10] ) - book_results = connector_manager.search(query, min_confidence=min_confidence) - data = { - "book_results": book_results, - "user_results": user_results, - "list_results": list_results, - "query": query or "", - } + data["book_results"] = connector_manager.search( + query, min_confidence=min_confidence + ) return TemplateResponse(request, "search_results.html", data)