Search lists
This commit is contained in:
parent
ec7a9f68c2
commit
e865530142
|
@ -63,17 +63,36 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<h2 class="title">Matching Users</h2>
|
<section class="block">
|
||||||
{% if not user_results %}
|
<h2 class="title">Matching Users</h2>
|
||||||
<p>No users found for "{{ query }}"</p>
|
{% if not user_results %}
|
||||||
{% endif %}
|
<p>No users found for "{{ query }}"</p>
|
||||||
{% for result in user_results %}
|
{% endif %}
|
||||||
<div class="block">
|
<ul>
|
||||||
{% include 'snippets/avatar.html' with user=result %}</h2>
|
{% for result in user_results %}
|
||||||
{% include 'snippets/username.html' with user=result show_full=True %}</h2>
|
<li class="block">
|
||||||
{% include 'snippets/follow_button.html' with user=result %}
|
{% include 'snippets/avatar.html' with user=result %}</h2>
|
||||||
</div>
|
{% include 'snippets/username.html' with user=result show_full=True %}</h2>
|
||||||
{% endfor %}
|
{% include 'snippets/follow_button.html' with user=result %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<section class="block">
|
||||||
|
<h2 class="title">Lists</h2>
|
||||||
|
{% if not list_results %}
|
||||||
|
<p>No lists found for "{{ query }}"</p>
|
||||||
|
{% endif %}
|
||||||
|
{% for result in list_results %}
|
||||||
|
<div class="block">
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<a href="{% url 'list' result.id %}">{{ result.name }}</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
|
@ -10,7 +10,7 @@ from django.views import View
|
||||||
from bookwyrm import models
|
from bookwyrm import models
|
||||||
from bookwyrm.connectors import connector_manager
|
from bookwyrm.connectors import connector_manager
|
||||||
from bookwyrm.utils import regex
|
from bookwyrm.utils import regex
|
||||||
from .helpers import is_api_request
|
from .helpers import is_api_request, privacy_filter
|
||||||
from .helpers import handle_remote_webfinger
|
from .helpers import handle_remote_webfinger
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ class Search(View):
|
||||||
if re.match(r'\B%s' % regex.full_username, query):
|
if re.match(r'\B%s' % regex.full_username, query):
|
||||||
handle_remote_webfinger(query)
|
handle_remote_webfinger(query)
|
||||||
|
|
||||||
# do a local user search
|
# do a user search
|
||||||
user_results = models.User.objects.annotate(
|
user_results = models.User.objects.annotate(
|
||||||
similarity=Greatest(
|
similarity=Greatest(
|
||||||
TrigramSimilarity('username', query),
|
TrigramSimilarity('username', query),
|
||||||
|
@ -42,12 +42,25 @@ class Search(View):
|
||||||
similarity__gt=0.5,
|
similarity__gt=0.5,
|
||||||
).order_by('-similarity')[:10]
|
).order_by('-similarity')[:10]
|
||||||
|
|
||||||
|
# any relevent lists?
|
||||||
|
list_results = privacy_filter(
|
||||||
|
request.user, models.List.objects, ['public', 'followers']
|
||||||
|
).annotate(
|
||||||
|
similarity=Greatest(
|
||||||
|
TrigramSimilarity('name', query),
|
||||||
|
TrigramSimilarity('description', query),
|
||||||
|
)
|
||||||
|
).filter(
|
||||||
|
similarity__gt=0.1,
|
||||||
|
).order_by('-similarity')[:10]
|
||||||
|
|
||||||
book_results = connector_manager.search(
|
book_results = connector_manager.search(
|
||||||
query, min_confidence=min_confidence)
|
query, min_confidence=min_confidence)
|
||||||
data = {
|
data = {
|
||||||
'title': 'Search Results',
|
'title': 'Search Results',
|
||||||
'book_results': book_results,
|
'book_results': book_results,
|
||||||
'user_results': user_results,
|
'user_results': user_results,
|
||||||
|
'list_results': list_results,
|
||||||
'query': query,
|
'query': query,
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'search_results.html', data)
|
return TemplateResponse(request, 'search_results.html', data)
|
||||||
|
|
Loading…
Reference in New Issue