lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bryzek.Michael" <>
Subject RE: Sorting on distance from a long/lat
Date Mon, 20 Nov 2006 20:30:48 GMT
Our general approach is:

  * Rewrite the query to compute the min and max latitude and longitude, essentially drawing
a box around the coordinate to find all documents within the range. This provides for an efficient
constant range query to find the total, unordered document set. This is much faster than trying
to do a distance calculation between all documents.

  * Run the search once internally, and compute the distance between all matching results.
Generally, this requires about 1000 distance calculations for our document set

  * Run the search again using our now populated search comparator to return ordered results
back to the user

Our approach is also rather inefficient for queries that return a large number of documents,
but we could not find a feasible way to precompute the distance between lat/long pairs in
advance. I'm also interested in hearing other ideas/approaches.


-----Original Message-----
From: spamsucks []
Sent: Mon 11/20/06 2:05 PM
Subject: Sorting on distance from a long/lat
I am successfully able to search for "nearbys" given a longitude and a 
latitude.  The basic summary of how I do this is that I add 1000 to the 
long/lat values and use a RangeFilter in my query.

In my display results, I display the results ordered by distance from the 
original long/lat.  What I do is calulate the distance for every document in 
my result from the original long/lat and perform a sort of the distance.

Doing the sort this way (calculating the distances for all results 
documents) feels like I am being inefficient and wasteful with my CPU 
cycles.  In most cases, I am only displaying the closest 10 documents, but I 
need to calculate the distance for all documents (potentially 1000) in order 
to come up with the 10 closest.

Has anyone wrestled with these questions before?  Is there another approache 
that I can take?

Here is my current working implementation, so you can see what I am 
describing.  The long/lat is stored in a database that I use to build up my 
lucene query/filters,Phillip

To unsubscribe, e-mail:
For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message