Question

I'm having a problem with Solr 3.4, I'm using it's spacial search functions like Geodist, and Geofilt. Everything seems ok and the results are return supposedly sorted by distance form a given center point.

However since Solr 3.4 lacks the ability to return function results in the data I had to calculate it manually (by PHP in this case).

I read the docs and the geodist should be a function that implements the haversine function of geo distance between 2 lat/lng points. I ported the function to PHP (easy!), and made sure that it give correct result.

The problem is: Solr calculate the distance in different formula that I couldn't find. So when I re-calculate the distance in PHP it results a inconsistent data distances (e.g. 132Mile instead of 83Mile), that's not a difference I can tolerate.

My Solution: I said OK it's handy to create a function comparison to see if I made a mistake in my port to the data, I dug into Solr code and extracted the literal implementation of havesine in org.apache.solr.search.function.distance.HaversineConstFunction, and the result was almost identical. and made this testing script (full source code and data).

My conclusion that Solr (or Lucene) does not use haversine as a geodist implemenation. But I don't know which equation.

UPDATE The bug was resolved. I think I went too far with my tests. The incorrect results occurred because of wrong parameter naming, I was using order (the one from SQL) instead of sort (Solr convention) to change the order of the results from the Solr web-service.

Was it helpful?

Solution

See the update, bug have been resolved. Thanks to @jarnbjo, and @TreyA for reminding me of a stupid issue. I should look to stupid mistakes in my code before debugging the libraries code in the future.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top