#community-help

Querying Full Names in Typesense

TLDR clem enquired on how to query full names with spaces in Typesense and attempted solving this by removing the spaces. Kishore Nallan explained Typesense prioritizes exact matches and no preprocessing is required. clem realized the problem was with their client, not Typesense.

Powered by Struct AI
5
24mo
Solved
Join the chat
Sep 06, 2021 (24 months ago)
clem
Photo of md5-cee46c31984a98d4d3b58844708480cb
clem
02:33 AM
hi typesense friends,

I hope everybody is enjoying their sunday night. quick question for you: assume that i have a users table with the following attributes:
id
givenName
familyName
fullName
fullName can have values with a space such as: John Smith or Bob Bert. Now i want to query by the full name, meaning my user should be able to query for John Smith

The way I want to approach this is by doing the following:
1. add a call back on the server side where anytime fullName is updated, it will set a new attribute called trimmedFullName (which will be remove the space):
a. John Smith => JohnSmith
2. on the client, I will also trim the search parameter and then search against trimmedFullName instead of fullName

Is this the right way to do this?

apologies, I jumped the gun and it was an issue on the client side where the presence of the space in the url was not triggering the search… indeed the typesense search works like a charm with the space, i just tested in postman
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:34 AM
👋 Yes, this will work but Typesense will prioritise exact matches in the results by default, so you don't have to do any special pre-processing of full name.
02:35
Kishore Nallan
02:35 AM
?q=john smith&query_by=fullName should already surface exact "John Smith" records at the top.
clem
Photo of md5-cee46c31984a98d4d3b58844708480cb
clem
02:40 AM
Kishore Nallan apologies, I jumped the gun and it was an issue on the client side where the presence of the space in the url was not triggering the search… indeed the typesense search works like a charm with the space, i just tested in postman
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:41 AM
Awesome, no worries