From a3db260e08174c463c83dc6368df4d24319cbfa3 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Sun, 29 Mar 2020 02:42:11 +0000 Subject: [PATCH] Allow searching for members by email --- apiserver/apiserver/api/utils.py | 9 ++++++++- apiserver/apiserver/api/views.py | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index d8df452..ea59b6d 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -143,7 +143,14 @@ def gen_search_strings(): string = '{} {}'.format( m.preferred_name, m.last_name, - ).lower() + ) + + if m.old_email: + string += ' ' + m.old_email + if m.user: + string += ' ' + m.user.email + + string = string.lower() search_strings[string] = m.id cache.set('search_strings', search_strings) diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index 954bf04..421a62f 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -69,8 +69,8 @@ class SearchViewSet(Base, Retrieve): # then get exact substring matches results += [x for x in choices if search in x] - if len(results) == 0 and len(search) >= 3: - # then get fuzzy matches + if len(results) == 0 and len(search) >= 3 and '@' not in search: + # then get fuzzy matches, but not for emails fuzzy_results = process.extract(search, choices, limit=NUM_SEARCH_RESULTS, scorer=fuzz.token_set_ratio) results += [x[0] for x in fuzzy_results]