mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-11 09:45:27 +00:00
Search local users as well as webfinger
This commit is contained in:
parent
b36b306934
commit
aa2e4da6f0
2 changed files with 14 additions and 4 deletions
|
@ -24,7 +24,7 @@
|
|||
</section>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not results %}
|
||||
{% if not book_results %}
|
||||
<p>No books found for "{{ query }}"</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import re
|
||||
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
from django.contrib.postgres.search import SearchRank, SearchVector
|
||||
from django.db.models import Avg, Count, Q
|
||||
from django.http import HttpResponseBadRequest, HttpResponseNotFound,\
|
||||
JsonResponse
|
||||
|
@ -153,11 +154,20 @@ def search(request):
|
|||
book_results = books_manager.local_search(query)
|
||||
return JsonResponse([r.__dict__ for r in book_results], safe=False)
|
||||
|
||||
user_results = []
|
||||
# use webfinger looks like a mastodon style account@domain.com username
|
||||
if re.match(r'\w+@\w+.\w+', query):
|
||||
# if something looks like a username, search with webfinger
|
||||
user_results = outgoing.handle_remote_webfinger(query)
|
||||
outgoing.handle_remote_webfinger(query)
|
||||
|
||||
# do a local user search
|
||||
vector = SearchVector('localname', weight='A') + \
|
||||
SearchVector('username', wieght='A')
|
||||
user_results = models.User.objects.annotate(
|
||||
search=vector
|
||||
).annotate(
|
||||
rank=SearchRank(vector, query)
|
||||
).filter(
|
||||
rank__gt=0
|
||||
).order_by('-rank')[:10]
|
||||
|
||||
book_results = books_manager.search(query)
|
||||
data = {
|
||||
|
|
Loading…
Reference in a new issue