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:
Chris Hill-Scott
2018-03-06 12:39:58 +00:00
parent 209d75efd9
commit faaea75a99
2 changed files with 40 additions and 0 deletions

View File

@@ -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)),