-
Notifications
You must be signed in to change notification settings - Fork 353
Open
Labels
Description
Bug Report
Problematic behavior
If you search a user whose name contains a "é" you won't find it
Expected behavior/code
The search user function shouldn't be senstitive to that. It should translate "é" to "e"
Steps to Reproduce
- Click on share
- Type Josué
- See no results
- Type Josue
- See results
Possible solution
Search users is only based on the email, it should search on the full name as well.
docs/src/backend/core/api/viewsets.py
Lines 164 to 202 in a09bd6c
def get_queryset(self): | |
""" | |
Limit listed users by querying the email field with a trigram similarity | |
search if a query is provided. | |
Limit listed users by excluding users already in the document if a document_id | |
is provided. | |
""" | |
queryset = self.queryset | |
if self.action != "list": | |
return queryset | |
# Exclude all users already in the given document | |
if document_id := self.request.query_params.get("document_id", ""): | |
queryset = queryset.exclude(documentaccess__document_id=document_id) | |
if not (query := self.request.query_params.get("q", "")) or len(query) < 5: | |
return queryset.none() | |
# For emails, match emails by Levenstein distance to prevent typing errors | |
if "@" in query: | |
return ( | |
queryset.annotate( | |
distance=RawSQL("levenshtein(email::text, %s::text)", (query,)) | |
) | |
.filter(distance__lte=3) | |
.order_by("distance", "email")[: settings.API_USERS_LIST_LIMIT] | |
) | |
# Use trigram similarity for non-email-like queries | |
# For performance reasons we filter first by similarity, which relies on an | |
# index, then only calculate precise similarity scores for sorting purposes | |
return ( | |
queryset.filter(email__trigram_word_similar=query) | |
.annotate(similarity=TrigramSimilarity("email", query)) | |
.filter(similarity__gt=0.2) | |
.order_by("-similarity", "email")[: settings.API_USERS_LIST_LIMIT] | |
) | |
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
To do