mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
Do more normalisation for better partial matching
Phone numbers sometimes contain stuff we normalise out. This matches perfectly if we have a full phone number, because we can normalise the thing we’re searching for in the same way as the search term. With partial search terms we can’t do this completely, because we can’t work out if ‘123’ is part of a UK number, an international number, the start of the phone number, the last 3 digits, etc. What we can do is remove some stuff that we can know will cause partial search terms to not match: - leading pluses - leading `0`s - any brackets - any spaces
This commit is contained in:
@@ -444,6 +444,11 @@ def dao_get_notifications_by_to_field(service_id, search_term, statuses=None):
|
||||
except InvalidEmailError:
|
||||
normalised = search_term
|
||||
|
||||
for character in ['(', ')', ' ']:
|
||||
normalised = normalised.replace(character, '')
|
||||
|
||||
normalised = normalised.lstrip('+0')
|
||||
|
||||
filters = [
|
||||
Notification.service_id == service_id,
|
||||
Notification.normalised_to.like("%{}%".format(normalised)),
|
||||
|
||||
Reference in New Issue
Block a user