haiwen / seahub

The web end of seafile server.
seafile.com
Other
525 stars 369 forks source link

More versatile user search functionality #6024

Open moschlar opened 4 months ago

moschlar commented 4 months ago

Since we're having quite a huge amount of users from different institutions, the need for more advances user search functionality has arisen!

Specifically, a user asked whether searching for a user in the sharing dialog (and thereby using the search-user API) can be augmented to also search in the institution field.

Now I understand that it might be difficult to simply use all words from the search query string to also search for institutions as that would be kind of fuzzy. Maybe a more easy and useful solution would be to simply add a checkbox to toggle whether to search users only in the own institution (or a selection listing all available institutions?)?


From the admin side of things, I would like to have a configurable option to specify how many results the search function shall return (currently hardcoded to 10).


FWIW, as a small workaround for convenience, I added the following custom function, which tries to at least sort the list such that users from the own institution (or having the same email domain) are listed first:

def custom_search_user(request, emails):
    emails_front, emails_back = [], []

    institution_name = ''

    username = request.user.username
    user_domain = username.split('@', 1)[1]
    profile = Profile.objects.get_profile_by_user(username)
    if profile:
        institution_name = profile.institution

    for email in emails:
        email_domain = email.split('@', 1)[1]
        if email_domain == user_domain:
            emails_front.append(email)
        else:
            p = Profile.objects.get_profile_by_user(email)
            logger.debug(f'{email=} {p=}')
            if p and p.institution and institution_name in p.institution:
                emails_front.append(email)
            else:
                emails_back.append(email)

    logger.debug(f'{emails_front=} {emails_back=}')
    return emails_front + emails_back
freeplant commented 4 months ago

From the admin side of things, I would like to have a configurable option to specify how many results the search function shall return (currently hardcoded to 10)

When we design the feature, we think there will not be too many people with same name. When a user refine the search characters, there should be less and less people matching. So I think 10 is enough. If it does meet your case, please send us more information regarding the issue.