You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Development Team <de...@gmail.com> on 2009/04/14 23:31:53 UTC

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.

RE: Sort by distance from location?

Posted by Ensdorf Ken <En...@zoominfo.com>.
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.qa@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.

Re: Sort by distance from location?

Posted by Development Team <de...@gmail.com>.
Ah, good question:  Yes, we've tried it... and it was slower. To give some
avg times:
Regular non-distance Searches: 100ms
Our expanding-criteria solution:  600ms
LocalSolr:  800ms

(We also had problems with LocalSolr in that the results didn't seem to be
cached in Solr upon doing a search. So each page of results meant another
800ms.)

- Daryl.


On Tue, Apr 14, 2009 at 5:34 PM, Smiley, David W. <ds...@mitre.org> wrote:

>  Have you tried LocalSolr?
> http://www.gissearch.com/localsolr
> (I haven’t but looks cool)
>

Re: Sort by distance from location?

Posted by "Smiley, David W." <ds...@mitre.org>.
Have you tried LocalSolr?
http://www.gissearch.com/localsolr
(I haven't but looks cool)


On 4/14/09 5:31 PM, "Development Team" <de...@gmail.com> wrote:

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.