mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Don't search remote sources by default
This commit is contained in:
parent
cb6c0035d7
commit
499c4e3267
3 changed files with 86 additions and 10 deletions
|
@ -1,9 +1,74 @@
|
|||
{% extends 'search/layout.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block panel %}
|
||||
|
||||
{% for result in results %}
|
||||
hi
|
||||
{% if results %}
|
||||
{% with results|first as local_results %}
|
||||
<ul class="block">
|
||||
{% for result in local_results.results %}
|
||||
<li class="pd-4">
|
||||
{% include 'snippets/search_result_text.html' with result=result %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endwith %}
|
||||
|
||||
<div class="block">
|
||||
{% for result_set in results|slice:"1:" %}
|
||||
{% if result_set.results %}
|
||||
<section class="box has-background-white-bis">
|
||||
{% if not result_set.connector.local %}
|
||||
<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 %}
|
||||
|
||||
<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="mb-5">
|
||||
{% include 'snippets/search_result_text.html' with result=result remote_result=True %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% if not remote %}
|
||||
<p class="block">
|
||||
{% if request.user.is_authenticated %}
|
||||
<a href="{{ request.path }}?q={{ query }}&type=book&remote=true">
|
||||
{% trans "Load results from other catalogues" %}
|
||||
</a>
|
||||
{% else %}
|
||||
<a href="{% url 'login' %}">
|
||||
{% trans "Log in to import or add books." %}
|
||||
</a>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -39,9 +39,11 @@
|
|||
<li{% if type == "book" %} class="is-active"{% endif %}>
|
||||
<a href="{% url 'search' %}?q={{ query }}&type=book">{% trans "Books" %}</a>
|
||||
</li>
|
||||
{% if request.user.is_authenticated %}
|
||||
<li{% if type == "user" %} class="is-active"{% endif %}>
|
||||
<a href="{% url 'search' %}?q={{ query }}&type=user">{% trans "Users" %}</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li{% if type == "list" %} class="is-active"{% endif %}>
|
||||
<a href="{% url 'search' %}?q={{ query }}&type=list">{% trans "Lists" %}</a>
|
||||
</li>
|
||||
|
@ -49,13 +51,13 @@
|
|||
</nav>
|
||||
|
||||
<section class="block">
|
||||
{% block panel %}
|
||||
{% endblock %}
|
||||
{% if not results %}
|
||||
<p>
|
||||
<em>{% blocktrans %}No results found for "{{ query }}"{% endblocktrans %}</em>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% block panel %}
|
||||
{% endblock %}
|
||||
</section>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ class Search(View):
|
|||
query = request.GET.get("q")
|
||||
min_confidence = request.GET.get("min_confidence", 0.1)
|
||||
search_type = request.GET.get("type")
|
||||
search_remote = request.GET.get("remote", False)
|
||||
|
||||
if is_api_request(request):
|
||||
# only return local book results via json so we don't cascade
|
||||
|
@ -41,23 +42,31 @@ class Search(View):
|
|||
}
|
||||
if not search_type in endpoints:
|
||||
search_type = "book"
|
||||
endpoint = endpoints[search_type]
|
||||
|
||||
data = {
|
||||
"query": query or "",
|
||||
"type": search_type,
|
||||
"results": endpoint(query, request.user, min_confidence) if query else {},
|
||||
"remote": search_remote,
|
||||
}
|
||||
if query:
|
||||
data["results"] = endpoints[search_type](
|
||||
query, request.user, min_confidence, search_remote
|
||||
)
|
||||
|
||||
return TemplateResponse(request, "search/{:s}.html".format(search_type), data)
|
||||
|
||||
|
||||
def book_search(query, _, min_confidence):
|
||||
def book_search(query, _, min_confidence, search_remote=False):
|
||||
"""the real business is elsewhere"""
|
||||
return connector_manager.search(query, min_confidence=min_confidence)
|
||||
if search_remote:
|
||||
return connector_manager.search(query, min_confidence=min_confidence)
|
||||
results = connector_manager.local_search(query, min_confidence=min_confidence)
|
||||
if not results:
|
||||
return None
|
||||
return [{"results": results}]
|
||||
|
||||
|
||||
def user_search(query, viewer, _):
|
||||
def user_search(query, viewer, *_):
|
||||
"""cool kids members only user search"""
|
||||
# logged out viewers can't search users
|
||||
if not viewer.is_authenticated:
|
||||
|
@ -83,7 +92,7 @@ def user_search(query, viewer, _):
|
|||
)
|
||||
|
||||
|
||||
def list_search(query, viewer, _):
|
||||
def list_search(query, viewer, *_):
|
||||
"""any relevent lists?"""
|
||||
return (
|
||||
privacy_filter(
|
||||
|
|
Loading…
Reference in a new issue