Merge pull request #1017 from bookwyrm-social/search-page

Search page tweaks
This commit is contained in:
Mouse Reeve 2021-04-29 13:35:39 -07:00 committed by GitHub
commit c30125aaa0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 168 additions and 88 deletions

View file

@ -6,7 +6,7 @@ from .abstract_connector import AbstractMinimalConnector, SearchResult
class Connector(AbstractMinimalConnector):
"""this is basically just for search"""
def get_or_create_book(self, remote_id, work=None):
def get_or_create_book(self, remote_id):
return activitypub.resolve_remote_id(remote_id, model=models.Edition)
def parse_search_data(self, data):

View file

@ -69,6 +69,10 @@ class Connector(AbstractConnector):
return search_results
def format_search_result(self, search_result):
cover = None
if search_result.cover:
cover = "%s%s" % (self.covers_url, search_result.cover)
return SearchResult(
title=search_result.title,
key=search_result.remote_id,
@ -77,7 +81,7 @@ class Connector(AbstractConnector):
if search_result.published_date
else None,
connector=self,
cover="%s%s" % (self.covers_url, search_result.cover),
cover=cover,
confidence=search_result.rank if hasattr(search_result, "rank") else 1,
)

View file

@ -11,10 +11,15 @@
<div class="block columns">
<div class="column">
<h2 class="title">{% trans "Matching Books" %}</h2>
<h2 class="title is-4">{% trans "Matching Books" %}</h2>
<section class="block">
{% if not local_results.results %}
<p>{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}</p>
<p><em>{% blocktrans %}No books found for "{{ query }}"{% endblocktrans %}</em></p>
{% if not user.is_authenticated %}
<p>
<a href="{% url 'login' %}">{% trans "Log in to import or add books." %}</a>
</p>
{% endif %}
{% else %}
<ul>
{% for result in local_results.results %}
@ -29,39 +34,56 @@
{% if request.user.is_authenticated %}
{% if book_results|slice:":1" and local_results.results %}
<div class="block">
<p>
<h3 class="title is-6 mb-0">
{% trans "Didn't find what you were looking for?" %}
</p>
</h3>
{% trans "Show results from other catalogues" as button_text %}
{% include 'snippets/toggle/open_button.html' with text=button_text small=True controls_text="more-results" %}
{% if local_results.results %}
{% trans "Hide results from other catalogues" as button_text %}
{% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results" %}
{% endif %}
</div>
{% endif %}
<div class="{% if local_results.results %}is-hidden{% endif %}" id="more-results">
{% for result_set in book_results|slice:"1:" %}
{% if result_set.results %}
<section class="block">
<section class="box has-background-white-bis">
{% if not result_set.connector.local %}
<h3 class="title is-5">
Results from <a href="{{ result_set.connector.base_url }}" target="_blank">{% if result_set.connector.name %}{{ result_set.connector.name }}{% else %}{{ result_set.connector.identifier }}{% endif %}</a>
</h3>
<header class="columns is-mobile">
<div class="column">
<h3 class="title is-5">
Results from
<a href="{{ result_set.connector.base_url }}" target="_blank">{{ result_set.connector.name|default:result_set.connector.identifier }}</a>
</h3>
</div>
<div class="column is-narrow">
{% trans "Show" as button_text %}
{% include 'snippets/toggle/open_button.html' with text=button_text small=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier class="is-small" icon="arrow-down" pressed=forloop.first %}
</div>
</header>
{% endif %}
<ul>
{% for result in result_set.results %}
<li class="pb-4">
{% include 'snippets/search_result_text.html' with result=result remote_result=True %}
</li>
{% endfor %}
</ul>
<div class="box has-background-white is-shadowless{% if not forloop.first %} is-hidden{% endif %}" id="more-results-panel-{{ result_set.connector.identifier }}">
<div class="is-flex is-flex-direction-row-reverse">
<div>
{% trans "Close" as button_text %}
{% include 'snippets/toggle/toggle_button.html' with label=button_text class="delete" nonbutton=True controls_text="more-results-panel" controls_uid=result_set.connector.identifier pressed=forloop.first %}
</div>
<ul class="is-flex-grow-1">
{% for result in result_set.results %}
<li class="pb-4">
{% include 'snippets/search_result_text.html' with result=result remote_result=True %}
</li>
{% endfor %}
</ul>
</div>
</div>
</section>
{% endif %}
{% endfor %}
{% if local_results.results %}
{% trans "Hide results from other catalogues" as button_text %}
{% include 'snippets/toggle/close_button.html' with text=button_text small=True controls_text="more-results" %}
{% endif %}
</div>
<div class="block">
@ -70,10 +92,11 @@
{% endif %}
</div>
<div class="column">
<section class="block">
<h2 class="title">{% trans "Matching Users" %}</h2>
{% if request.user.is_authenticated %}
<section class="box">
<h2 class="title is-4">{% trans "Matching Users" %}</h2>
{% if not user_results %}
<p>{% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}</p>
<p><em>{% blocktrans %}No users found for "{{ query }}"{% endblocktrans %}</em></p>
{% endif %}
<ul>
{% for result in user_results %}
@ -87,10 +110,11 @@
{% endfor %}
</ul>
</section>
<section class="block">
<h2 class="title">{% trans "Lists" %}</h2>
{% endif %}
<section class="box">
<h2 class="title is-4">{% trans "Lists" %}</h2>
{% if not list_results %}
<p>{% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}</p>
<p><em>{% blocktrans %}No lists found for "{{ query }}"{% endblocktrans %}</em></p>
{% endif %}
{% for result in list_results %}
<div class="block">

View file

@ -43,7 +43,7 @@ urlpatterns = [
re_path("^api/updates/notifications/?$", views.get_notification_count),
re_path("^api/updates/stream/(?P<stream>[a-z]+)/?$", views.get_unread_status_count),
# authentication
re_path(r"^login/?$", views.Login.as_view()),
re_path(r"^login/?$", views.Login.as_view(), name="login"),
re_path(r"^register/?$", views.Register.as_view()),
re_path(r"^logout/?$", views.Logout.as_view()),
re_path(r"^password-reset/?$", views.PasswordResetRequest.as_view()),

View file

@ -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)

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-29 11:36-0700\n"
"POT-Creation-Date: 2021-04-29 13:24-0700\n"
"PO-Revision-Date: 2021-03-02 17:19-0800\n"
"Last-Translator: Mouse Reeve <mousereeve@riseup.net>\n"
"Language-Team: English <LL@li.org>\n"
@ -282,7 +282,7 @@ msgstr "Orte"
#: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65
#: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12
#: bookwyrm/templates/search_results.html:91
#: bookwyrm/templates/search_results.html:115
#: bookwyrm/templates/user/user_layout.html:62
msgid "Lists"
msgstr "Listen"
@ -581,6 +581,7 @@ msgstr "Veröffentlicht von %(publisher)s."
#: bookwyrm/templates/feed/feed_layout.html:70
#: bookwyrm/templates/get_started/layout.html:19
#: bookwyrm/templates/get_started/layout.html:52
#: bookwyrm/templates/search_results.html:72
msgid "Close"
msgstr "Schließen"
@ -1129,7 +1130,7 @@ msgid "Search for a user"
msgstr "Suche nach Buch oder Benutzer*in"
#: bookwyrm/templates/get_started/users.html:13
#: bookwyrm/templates/search_results.html:76
#: bookwyrm/templates/search_results.html:99
#, python-format
msgid "No users found for \"%(query)s\""
msgstr "Keine Nutzer*innen für \"%(query)s\" gefunden"
@ -1908,23 +1909,33 @@ msgstr "Profil"
msgid "Relationships"
msgstr "Beziehungen"
#: bookwyrm/templates/search_results.html:33
#: bookwyrm/templates/search_results.html:20
msgid "Log in to import or add books."
msgstr ""
#: bookwyrm/templates/search_results.html:38
msgid "Didn't find what you were looking for?"
msgstr "Nicht gefunden, wonach du gesucht hast?"
#: bookwyrm/templates/search_results.html:35
#: bookwyrm/templates/search_results.html:40
msgid "Show results from other catalogues"
msgstr "Ergebnisse aus anderen Katalogen zeigen"
#: bookwyrm/templates/search_results.html:62
#: bookwyrm/templates/search_results.html:44
msgid "Hide results from other catalogues"
msgstr "Ergebnisse aus anderen Katalogen ausblenden"
#: bookwyrm/templates/search_results.html:74
#: bookwyrm/templates/search_results.html:63
#, fuzzy
#| msgid "Show more"
msgid "Show"
msgstr "Mehr anzeigen"
#: bookwyrm/templates/search_results.html:97
msgid "Matching Users"
msgstr "Passende Nutzer*innen"
#: bookwyrm/templates/search_results.html:93
#: bookwyrm/templates/search_results.html:117
#, python-format
msgid "No lists found for \"%(query)s\""
msgstr "Keine Liste für \"%(query)s\" gefunden"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-29 11:36-0700\n"
"POT-Creation-Date: 2021-04-29 13:24-0700\n"
"PO-Revision-Date: 2021-02-28 17:19-0800\n"
"Last-Translator: Mouse Reeve <mousereeve@riseup.net>\n"
"Language-Team: English <LL@li.org>\n"
@ -261,7 +261,7 @@ msgstr ""
#: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65
#: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12
#: bookwyrm/templates/search_results.html:91
#: bookwyrm/templates/search_results.html:115
#: bookwyrm/templates/user/user_layout.html:62
msgid "Lists"
msgstr ""
@ -535,6 +535,7 @@ msgstr ""
#: bookwyrm/templates/feed/feed_layout.html:70
#: bookwyrm/templates/get_started/layout.html:19
#: bookwyrm/templates/get_started/layout.html:52
#: bookwyrm/templates/search_results.html:72
msgid "Close"
msgstr ""
@ -1032,7 +1033,7 @@ msgid "Search for a user"
msgstr ""
#: bookwyrm/templates/get_started/users.html:13
#: bookwyrm/templates/search_results.html:76
#: bookwyrm/templates/search_results.html:99
#, python-format
msgid "No users found for \"%(query)s\""
msgstr ""
@ -1739,23 +1740,31 @@ msgstr ""
msgid "Relationships"
msgstr ""
#: bookwyrm/templates/search_results.html:33
#: bookwyrm/templates/search_results.html:20
msgid "Log in to import or add books."
msgstr ""
#: bookwyrm/templates/search_results.html:38
msgid "Didn't find what you were looking for?"
msgstr ""
#: bookwyrm/templates/search_results.html:35
#: bookwyrm/templates/search_results.html:40
msgid "Show results from other catalogues"
msgstr ""
#: bookwyrm/templates/search_results.html:62
#: bookwyrm/templates/search_results.html:44
msgid "Hide results from other catalogues"
msgstr ""
#: bookwyrm/templates/search_results.html:74
#: bookwyrm/templates/search_results.html:63
msgid "Show"
msgstr ""
#: bookwyrm/templates/search_results.html:97
msgid "Matching Users"
msgstr ""
#: bookwyrm/templates/search_results.html:93
#: bookwyrm/templates/search_results.html:117
#, python-format
msgid "No lists found for \"%(query)s\""
msgstr ""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.0.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-29 11:36-0700\n"
"POT-Creation-Date: 2021-04-29 13:24-0700\n"
"PO-Revision-Date: 2021-03-19 11:49+0800\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -266,7 +266,7 @@ msgstr "Lugares"
#: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65
#: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12
#: bookwyrm/templates/search_results.html:91
#: bookwyrm/templates/search_results.html:115
#: bookwyrm/templates/user/user_layout.html:62
msgid "Lists"
msgstr "Listas"
@ -548,6 +548,7 @@ msgstr "Publicado por %(publisher)s."
#: bookwyrm/templates/feed/feed_layout.html:70
#: bookwyrm/templates/get_started/layout.html:19
#: bookwyrm/templates/get_started/layout.html:52
#: bookwyrm/templates/search_results.html:72
msgid "Close"
msgstr "Cerrar"
@ -1060,7 +1061,7 @@ msgid "Search for a user"
msgstr "Buscar un usuario"
#: bookwyrm/templates/get_started/users.html:13
#: bookwyrm/templates/search_results.html:76
#: bookwyrm/templates/search_results.html:99
#, python-format
msgid "No users found for \"%(query)s\""
msgstr "No se encontró ningún usuario correspondiente a \"%(query)s\""
@ -1811,23 +1812,33 @@ msgstr "Perfil"
msgid "Relationships"
msgstr "Relaciones"
#: bookwyrm/templates/search_results.html:33
#: bookwyrm/templates/search_results.html:20
msgid "Log in to import or add books."
msgstr ""
#: bookwyrm/templates/search_results.html:38
msgid "Didn't find what you were looking for?"
msgstr "¿No encontraste lo que buscabas?"
#: bookwyrm/templates/search_results.html:35
#: bookwyrm/templates/search_results.html:40
msgid "Show results from other catalogues"
msgstr "Mostrar resultados de otros catálogos"
#: bookwyrm/templates/search_results.html:62
#: bookwyrm/templates/search_results.html:44
msgid "Hide results from other catalogues"
msgstr "Ocultar resultados de otros catálogos"
#: bookwyrm/templates/search_results.html:74
#: bookwyrm/templates/search_results.html:63
#, fuzzy
#| msgid "Show more"
msgid "Show"
msgstr "Mostrar más"
#: bookwyrm/templates/search_results.html:97
msgid "Matching Users"
msgstr "Usuarios correspondientes"
#: bookwyrm/templates/search_results.html:93
#: bookwyrm/templates/search_results.html:117
#, python-format
msgid "No lists found for \"%(query)s\""
msgstr "No se encontró ningúna lista correspondiente a \"%(query)s\""

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-29 11:36-0700\n"
"POT-Creation-Date: 2021-04-29 13:24-0700\n"
"PO-Revision-Date: 2021-04-05 12:44+0100\n"
"Last-Translator: Fabien Basmaison <contact@arkhi.org>\n"
"Language-Team: Mouse Reeve <LL@li.org>\n"
@ -272,7 +272,7 @@ msgstr "Lieux"
#: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65
#: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12
#: bookwyrm/templates/search_results.html:91
#: bookwyrm/templates/search_results.html:115
#: bookwyrm/templates/user/user_layout.html:62
msgid "Lists"
msgstr "Listes"
@ -554,6 +554,7 @@ msgstr "Publié par %(publisher)s."
#: bookwyrm/templates/feed/feed_layout.html:70
#: bookwyrm/templates/get_started/layout.html:19
#: bookwyrm/templates/get_started/layout.html:52
#: bookwyrm/templates/search_results.html:72
msgid "Close"
msgstr "Fermer"
@ -1072,7 +1073,7 @@ msgid "Search for a user"
msgstr "Chercher un compte"
#: bookwyrm/templates/get_started/users.html:13
#: bookwyrm/templates/search_results.html:76
#: bookwyrm/templates/search_results.html:99
#, python-format
msgid "No users found for \"%(query)s\""
msgstr "Aucun compte trouvé pour « %(query)s»"
@ -1836,23 +1837,33 @@ msgstr "Profil"
msgid "Relationships"
msgstr "Relations"
#: bookwyrm/templates/search_results.html:33
#: bookwyrm/templates/search_results.html:20
msgid "Log in to import or add books."
msgstr ""
#: bookwyrm/templates/search_results.html:38
msgid "Didn't find what you were looking for?"
msgstr "Vous navez pas trouvé ce que vous cherchiez?"
#: bookwyrm/templates/search_results.html:35
#: bookwyrm/templates/search_results.html:40
msgid "Show results from other catalogues"
msgstr "Montrer les résultats dautres catalogues"
#: bookwyrm/templates/search_results.html:62
#: bookwyrm/templates/search_results.html:44
msgid "Hide results from other catalogues"
msgstr "Masquer les résultats dautres catalogues"
#: bookwyrm/templates/search_results.html:74
#: bookwyrm/templates/search_results.html:63
#, fuzzy
#| msgid "Show more"
msgid "Show"
msgstr "Déplier"
#: bookwyrm/templates/search_results.html:97
msgid "Matching Users"
msgstr "Comptes correspondants"
#: bookwyrm/templates/search_results.html:93
#: bookwyrm/templates/search_results.html:117
#, python-format
msgid "No lists found for \"%(query)s\""
msgstr "Aucune liste trouvée pour « %(query)s»"

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1.1\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-04-29 11:36-0700\n"
"POT-Creation-Date: 2021-04-29 13:24-0700\n"
"PO-Revision-Date: 2021-03-20 00:56+0000\n"
"Last-Translator: Kana <gudzpoz@live.com>\n"
"Language-Team: Mouse Reeve <LL@li.org>\n"
@ -270,7 +270,7 @@ msgstr "地点"
#: bookwyrm/templates/book/book.html:220 bookwyrm/templates/layout.html:65
#: bookwyrm/templates/lists/lists.html:5 bookwyrm/templates/lists/lists.html:12
#: bookwyrm/templates/search_results.html:91
#: bookwyrm/templates/search_results.html:115
#: bookwyrm/templates/user/user_layout.html:62
msgid "Lists"
msgstr "列表"
@ -552,6 +552,7 @@ msgstr "由 %(publisher)s 出版。"
#: bookwyrm/templates/feed/feed_layout.html:70
#: bookwyrm/templates/get_started/layout.html:19
#: bookwyrm/templates/get_started/layout.html:52
#: bookwyrm/templates/search_results.html:72
msgid "Close"
msgstr "关闭"
@ -1052,7 +1053,7 @@ msgid "Search for a user"
msgstr "搜索用户"
#: bookwyrm/templates/get_started/users.html:13
#: bookwyrm/templates/search_results.html:76
#: bookwyrm/templates/search_results.html:99
#, python-format
msgid "No users found for \"%(query)s\""
msgstr "没有找到 \"%(query)s\" 的用户"
@ -1801,23 +1802,33 @@ msgstr "个人资料"
msgid "Relationships"
msgstr "关系"
#: bookwyrm/templates/search_results.html:33
#: bookwyrm/templates/search_results.html:20
msgid "Log in to import or add books."
msgstr ""
#: bookwyrm/templates/search_results.html:38
msgid "Didn't find what you were looking for?"
msgstr "没有找到你想找的?"
#: bookwyrm/templates/search_results.html:35
#: bookwyrm/templates/search_results.html:40
msgid "Show results from other catalogues"
msgstr "显示其它类别的结果"
#: bookwyrm/templates/search_results.html:62
#: bookwyrm/templates/search_results.html:44
msgid "Hide results from other catalogues"
msgstr "隐藏其它类别的结果"
#: bookwyrm/templates/search_results.html:74
#: bookwyrm/templates/search_results.html:63
#, fuzzy
#| msgid "Show more"
msgid "Show"
msgstr "显示更多"
#: bookwyrm/templates/search_results.html:97
msgid "Matching Users"
msgstr "匹配的用户"
#: bookwyrm/templates/search_results.html:93
#: bookwyrm/templates/search_results.html:117
#, python-format
msgid "No lists found for \"%(query)s\""
msgstr "没有找到 \"%(query)s\" 的列表"