Search on username and localname in user search

This commit is contained in:
Mouse Reeve 2021-01-03 07:48:57 -08:00
parent 8afd111ff4
commit b5ce7a0c25

View file

@ -5,6 +5,7 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.postgres.search import TrigramSimilarity
from django.core.paginator import Paginator
from django.db.models import Avg, Q
from django.db.models.functions import Greatest
from django.http import HttpResponseNotFound, JsonResponse
from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404, redirect
@ -227,7 +228,10 @@ def search(request):
# do a local user search
user_results = models.User.objects.annotate(
similarity=TrigramSimilarity('username', query),
similarity=Greatest(
TrigramSimilarity('username', query),
TrigramSimilarity('localname', query),
)
).filter(
similarity__gt=0.5,
).order_by('-similarity')[:10]