#community-help

Resolving Geo-Distance Issue in Search Query Results

TLDR Guillermo and Andrew wanted to know individual distance of results when filtering by geopoint. Kishore Nallan advised checking 'geo_distance_meters' in the search response and ensure 'sort_by' clause is present in the query.

Powered by Struct AI
14
14mo
Solved
Join the chat
Jul 22, 2022 (14 months ago)
Guillermo
Photo of md5-6f48d9114b22b98994ccbbd9192d9718
Guillermo
02:06 PM
Hello! Is there a way of knowing the individual distance of each result when filtering by geopoint?
Andrew
Photo of md5-88d88db4789daa0e3abef8c3ca27772b
Andrew
02:07 PM
Oh .. I'd like to know that too!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:16 PM
Distance from the search query point?
Andrew
Photo of md5-88d88db4789daa0e3abef8c3ca27772b
Andrew
02:17 PM
That woud be what interests me, Kishore. I guess thats what Guillermo means, but he should confirm
Guillermo
Photo of md5-6f48d9114b22b98994ccbbd9192d9718
Guillermo
02:19 PM
Yes, exactly. I can sort them by distance to the search query point but I’d like to know exactly how close they are.
02:20
Guillermo
02:20 PM
Im guessing that information is available somewhere since the calculation is already been made
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
02:31 PM
Check the geo_distance_meters in the search response. You can see example in the response here: https://typesense.org/docs/0.23.1/api/geosearch.html#searching-within-a-radius
Andrew
Photo of md5-88d88db4789daa0e3abef8c3ca27772b
Andrew
02:31 PM
Thanks Kishore Nallan
Guillermo
Photo of md5-6f48d9114b22b98994ccbbd9192d9718
Guillermo
02:41 PM
Yes I saw that but its not showing up in the response. All I’m getting on every hit is ‘document’, ‘highlights’ and ‘text_match’.
02:42
Guillermo
02:42 PM
Trying to access geo_distance_meters returns null
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:00 PM
That field is only shown when you have a sort_by clause. Do you have that in your query? If not, can you post a minimally reproduceable example for me to run and check?
Guillermo
Photo of md5-6f48d9114b22b98994ccbbd9192d9718
Guillermo
03:02 PM
Ah I see. No, currently I’m not using sort_by
03:09
Guillermo
03:09 PM
Added the sort_by clause and that did it, Thank you!
Kishore Nallan
Photo of md5-4e872368b2b2668460205b409e95c2ea
Kishore Nallan
03:11 PM
Awesome. Without sort by there is no reference point for calculating the distance.