#community-help

Searching Phone Number Issues in Typesense.

TLDR Robert was having issues searching phone numbers using Typesense. CaptainCodeman suggested storing the number as segments, while Jason clarified that Typesense only supports prefix queries and suggested workarounds.

Powered by Struct AI

1

1

6
26mo
Solved
Join the chat
Nov 09, 2021 (26 months ago)
Robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
Robert
07:18 PM
hi everyone, i'm looking to utilize typesense to search an "address book" collection. So, think about an object that has the following properties: id:string, full_name:string, phone_number:string. I can search against full_name very well (and unless otherwise specified, it will match queries against all of the properties.) However, unless I have something within 0-2 typos, it will never match a query against phone_number. Any insight?
07:19
Robert
07:19 PM
So, if a document had a phone_number of +15553337895, and I tried to query against phone_number with "7895", it would not match. it will only match if I have x5553337895 (for 1 typo), xx553337895 (for 2 typos).
CaptainCodeman
Photo of md5-d3a4ca49ba4aeb3b9d0cb7d846eb0989
CaptainCodeman
08:52 PM
I’d probably store the individual “segments” of the number in an array for searching against (plus some combinations, e.g. the number without the country + area code)

1

Robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
Robert
09:05 PM
hmm, we're always storing the # in e164 format, so there aren't really segments. should I not expect typesenes to be able to suggest "+15553337895" when "7895" is the query?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
09:38 PM
Typesense (and most search engines) only support prefix queries. So +1, +15, +1555, etc will return <tel:+15553337895|+15553337895>, but searching for a sub-string that is not the start of the string like 7895 (non-prefix) will not return that record.

If you need to match sub-strings, I'd recommend breaking out the phone number into space separated sub-sections like <tel:15553337895|1 555 333 7895> or an array like CaptainCodeman mentions above. Or if you just need to search for last 4 digits, you could put just that in a separate field.
Robert
Photo of md5-0ca37054c6c9042aa04fcfb92cc7d99c
Robert
10:51 PM
Interesting. Thanks for the insight!

1