I'm playing with the new Solr 4 geospatial search. Like in an example from http://wiki.apache.org/solr/SolrAdaptersForLuceneSpatial4 I'm trying to get the results like so:
http://localhost:8983/solr/allopenhours/select?
&q=foobar
&fq=geo:%22Intersects(Circle(54.729696,-98.525391%20d=0.08992))%22
&q={!%20score=distance}
&fl=*,score
But it doesn't work. How can I get distance and score fields in the results set?
Solr field: sfield=store. Point to search/sort from: pt=36.35,-97.51.
Solr supports location data for use in spatial/geospatial searches. Using spatial search, you can: Index points or other shapes. Filter search results by a bounding box or circle or by other shapes. Sort or boost scoring by distance between points, or relative area between rectangles.
Trying a basic queryThe main query for a solr search is specified via the q parameter. Standard Solr query syntax is the default (registered as the “lucene” query parser). If this is new to you, please check out the Solr Tutorial. Adding debug=query to your request will allow you to see how Solr is parsing your query.
Spatial search is the task of identifying and investigating spatially distributed choice alternatives which serve as the basis for a locational decision.
According to the reference Spatial Search - Returning the distance you can edit your fields parameter to do one of the following:
&fl=*,score,geodist()
&fl=*,score,_dist_:geodist()
- this one will return the distance in the alias _dist_
The answer Paige gave is correct. However, the error is shown depending on query given.
Error parsing fieldname: geodist - not enough parameters:[]
geodist needs the sfield
(field which holds the location in the document) and a pt
(the central point of the circle). If it can't find any of these, it will throw the error shown.
Either add these two to the URL
&pt=52.373,4.899&sfield=store&fl=_dist_:geodist()
Or add the two (or actually 3: pt
, lat
and lon
) to the geodist()
function call:
&fl:_dist_:geodist(store,52.373,4.899)
Note that in the first case, if you have additional geo functions (like geofilt
) in your query, the pt
and sfield
are used for that as well (unless locally overridden)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With