I've never used them personally, but I think a function query would suit you here. Function queries allow you to define a custom function as a component of the score of a result document. Define a distance function based on the user's current location and the that of the search result, such that the shorter the distance, the higher the function output. This will boost results inversely proportional to the distance from the user.
-Ken > -----Original Message----- > From: Development Team [mailto:dev.and...@gmail.com] > Sent: Tuesday, April 14, 2009 5:32 PM > To: solr-user@lucene.apache.org > Subject: Sort by distance from location? > > Hi everybody, > My index has latitude/longitude values for locations. I am > required to > do a search based on a set of criteria, and order the results based on > how > far the lat/long location is to the current user's location. Currently > we > are emulating such a search by adding criteria of ever-widening > bounding > boxes, and the more of those boxes match the document, the higher the > score > and thus the closer ones appear at the start of the results. The query > looks > something like this (newlines between each search term): > > +criteraOne:1 > +criteriaTwo:true > +latitude:[-90.0 TO 90.0] +longitude:[-180.0 TO 180.0] > (latitude:[40.52 TO 40.81] longitude:[-74.17 TO -73.79]) > (latitude:[40.30 TO 41.02] longitude:[-74.45 TO -73.51]) > (latitude:[39.94 TO 41.38] longitude:[-74.93 TO -73.03]) > [[...etc...about 10 times...]] > > Naturally this is quite slow (query is approximately 6x slower > than > normal), and... I can't help but feel that there's a more elegant way > of > sorting by distance. > Does anybody know how to do this or have any suggestions? > > Sincerely, > > Daryl.