#community-help

Using Geo Location in Typesense Search Queries

TLDR GM is trying to use geo location in search queries using Typesense. Jason demonstrated the usage of an alias in the query and explained where to use it. However, GM has further questions on adding conditional searches.

Powered by Struct AI
Oct 25, 2022 (14 months ago)
GM
Photo of md5-9f364f57af6f71faaf6ea963342ef3f6
GM
05:38 PM
const searchParameters = {
q: '*',
query_by: 'ADDRESS_CITY',
filter_by: 'COORDINATES:(' + latitude + ',' + longitude + ', ' + radious + ')',
sort_by: 'COORDINATES(' + latitude + ',' + longitude + '):asc',
};

const results = (await typesense.aliases('active-sites').retrieve()).name.search(searchParameters);
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:39 PM
You can use the alias anywhere you use the collection name
GM
Photo of md5-9f364f57af6f71faaf6ea963342ef3f6
GM
05:40 PM
okay..let me check
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:40 PM
So for eg: typesense.collections('active-sites').documents().search(searchParameters)
05:40
Jason
05:40 PM
where active-sites is an alias name
GM
Photo of md5-9f364f57af6f71faaf6ea963342ef3f6
GM
05:41 PM
okay.how to add condition ..like
05:42
GM
05:42 PM
if geo location is availble then use geo..else use state search