#community-help

Using TypeSense for Geolocation Tagged Job Search

TLDR Nicholas needed help to enable geo-location based job search on a board. James suggested using filter_by from TypeSense, while Jason elaborated on 'OR' and 'AND' operations in TypeSense.

Powered by Struct AI

1

16
25mo
Solved
Join the chat
Oct 19, 2021 (25 months ago)
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
08:59 PM
Hi. I'm trying to power a job board and allow users to search jobs that are in one of multiple geo-locations or flagged as remote. Is that possible with TypeSense?
James
Photo of md5-ae7223c767d7228418baf97773be94d6
James
09:01 PM
I'm no expert but I THINK you're looking for this: https://typesense.org/docs/0.21.0/api/documents.html#geosearch
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
09:07 PM
Thanks James. Exactly that. But can I combine multiple locations, so query all records in one location OR another location?
James
Photo of md5-ae7223c767d7228418baf97773be94d6
James
09:15 PM
In that case I believe your search query would just need a filter_by statement. There is a decent example here: https://typesense.org/docs/0.21.0/api/documents.html#arguments
09:17
James
09:17 PM
I think it would be {filter_by: ['location-1', 'location-2']} in your search query (replacing locations with your actual like... locations
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
09:17 PM
Thanks! I'll give it a try.
James
Photo of md5-ae7223c767d7228418baf97773be94d6
James
09:18 PM
filter_by: locations:=['location-1', 'location-2'] I think. Assuming locations is the field you use to store that data.
09:19
James
09:19 PM
that might be a more accurate, working way (again, I'm not expert, just learning myself)
09:20
James
09:20 PM
They talk a little about filter_by syntax here in a previous message

https://typesense-community.slack.com/archives/C01P749MET0/p1626083075105300
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
10:31 PM
Nicholas When you say geo-locations, are these tagged with lat / lng or do they contain for eg: city and country names in your use case?
Oct 21, 2021 (25 months ago)
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
12:11 AM
Jason The locations would be tagged with lat/lng.
12:13
Nicholas
12:13 AM
The full query I'm going for might include a full-text search, be filtered to one or more types ("full time", "part time", "contract", etc) , one or more fields ("design", "engineering", etc), and one or more lat/lng geo-locations.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
12:28 AM
Nicholas Got it. Typesense currently only supports doing ORing values in the same field, and ANDing values across fields or same field. If you need to OR across fields, the work-around would be to send multiple queries using the multi_search endpoint, with each query having a particular field and then aggregating the results on the client side for these queries.
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
01:03 AM
Jason Thanks. Do the individual hits come back with some kind of relevance score that I can use to sort the aggregated results?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
01:04 AM
Yup, the _text_match score in each hit can be used to aggregate across requests
Nicholas
Photo of md5-8e5dc570a4fa7ff80428aba11c0b6968
Nicholas
01:04 AM
Perfect. Thanks.

1