5

How can we have Solr 3.6.1 return the Geospatial search results both filtered by bbox and sorted by distance?

I tried appending a &sort=geodist() asc to the URL as stated in the Solr docs, but I get the error:

sort param could not be parsed as a query, and is not a field that exists in the index: geodist()

Query URL with sort & bbox (NOT Working)

http://localhost8080/solr/select?wt=json&indent=true
&q=*:*
&fl=id,latlng
&fq={!bbox%20pt=42.352455,-71.048069%20sfield=latlng%20d=5}
&sort=geodist() asc

Query URL with sort (Works)

http://localhost:8080/solr/select?wt=json&indent=true
&fl=id,latlng
&q=*:*
&sfield=latlng
&pt=42.352455,-71.048069
&sort=geodist()%20asc

Query URL with bbox (Works)

http://localhost8080/solr/select?wt=json&indent=true
&q=*:*
&fl=id,latlng
&fq={!bbox%20pt=42.352455,-71.048069%20sfield=latlng%20d=5}

How can I have both bbox filtering and sort the results by distance (geodist())?

Nyxynyxx
  • 196
  • 3
  • 9

1 Answers1

5

Simply pull out the 'pt' and 'sfield' local-params you have into top-level query parameters, just as you did with the working sort query. Your fq will be just {!bbox d=5}

David Smiley
  • 4,102
  • 2
  • 19
  • 18
  • What is the reason for having to pull out `pt` and `sfield` parameters, but leaving `d` parameter within the curly braces? – Nyxynyx Sep 29 '12 at 15:14
  • So called "Query Parsers" like bbox first look for a parameter in its local-params and then fall back to the top URL parameters. They need to be at the top level so that geodist() will see them. – David Smiley Sep 29 '12 at 18:29