Radius search at lat, lon in AWS CloudSearch

Our company uses AWS CloudSearch to find and retrieve user data. User data consists of a position field of type lat, lon. Therefore, for a given radius and position, we have to find all users within the radius of the radius. How do I write a search query to extract the data I need?
We are using node.js as a server-side language.
 Please, help.

+3


source to share


3 answers


It is not possible to search for Latlons in a cloud search in radius. You can order the distance, but you can search in the radius.

Since you want to get all results in a radius. Instead, create a rectangle such that the four sides touch the circle you want to search in. You can now search within the rectangle rectangle and return results sorted by distance.

The downside is that there will be some results that are at the corners of the bounding box, so they are not in the circle, but they will appear as a result of the cloud search. You can use them as well as zoom or filter depending on the distance.

Here is an example query that does the same: q = user * & FQ = location% 3A% 5B% 2740.628611, -100.694152% 27% +2725.621966, -66.686706% 27% 5D & expr. geo = haversin% +2838,958687, -77,343149, location.latitude, location.longitude% 29 & sort = geo% 20asc



here: fq = location% 3A% 5B% 2740.628611, -100.694152% 27,% 2725.621966, -66.686706% 27% 5D ---> search in the Latlons bounding box, that is, in the upper left corner and in the lower right corner.

expr.geo = haversin% 2838.958687, -77.343149, location.latitude, location.longitude% 29 & sort = geo% 20asc ---> creates an expression that calculates the distance between LatLon in the search document to a fixed point (give this as the center of your circle). and returns the result sorted by distance.

Note that the haversin distance function calculates the distance between LatLons as the distance between two points on a perfect sphere.

+3


source


You want to rank the results based on the haversin function. This is equivalent to "searching in a radius" except for the fact that you are really interested in the distance on the surface of the sphere.

Here is an example of such a request from CloudSearch (from http://docs.aws.amazon.com/cloudsearch/latest/developerguide/searching-locations.html ):



q=restaurant&expr.distance=haversin(35.621966,-120.686706,location.latitude,location.longitude)&sort=distance asc

      

The choice of server language doesn't matter as CloudSearch only provides a REST interface. Check out the getting started guide if you haven't already. http://docs.aws.amazon.com/cloudsearch/latest/developerguide/getting-started.html

0


source


You can use the following query:

q=nikhil&expr.distance=haversin(35.621966,-120.686706,latlong.latitude,latlong.longitude)&sort=distance%20asc&return=distance

      

Then loop over each result and get an if condition

It is very slow and time consuming as the nodes will be larger depending on the data, but this is one answer to your question.

-1


source







All Articles