Function queries

In spatial search, along with returning matching documents within a given range, Solr also supports calculation of matching document distances from the search point and merging them in the returning response. Solr even supports sorting and boosting on the calculated distance. To calculate distances, the following are the functions available in Solr:

  • geodist: This calculates the distance between too points (latitude and longitude)
  • dist: Calculates the p-norm distance between multidimensional vectors
  • hsin: This calculates the distance between two points on a sphere
  • sqedist: Calculates the squared Euclidean distance between two points

From the preceding list, geodist is the most commonly used function for most search cases. It takes three optional parameters: sfield (spatial field defined in managed-schema.xml), latitude, and longitude. For example, we find all cities from the searching point (45.15, -93.85) within a radius of 50 kilometers, calculate their distance from the searched point, and return in the response:

&q=:&fq={!geofilt}&sfield=location&pt=45.15,-93.85&d=50&fl=id,city,distance:geodist()

Additionally, we sort by distance ascending. The following is the query:

&q=:&fq={!geofilt}&sfield=location&pt=45.15,-93.85&d=50&fl=id,city,distance:geodist()
&sort=geodist() asc

This is the basic overview of spatial search. There are many more spatial searching features available in Solr. Exploring every feature here is not possible. However, we can take this chapter as a reference and explore more spatial search features. Rather than going into more details of spatial search, let's move on to the next chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.63.138