The future of geo-spatial searches with Lucene
Or: Introducing Spatial4n
The Lucene spatial contrib module has been a nice addition to Lucene, but for a while now too many bug reports have been piling up, and it got to a point where it was clear something was broken somewhere deep inside. Luckily, a bunch of good people started writing their own general purpose geo-spatial library in Java, and provided a Lucene module to interact with it to provide spatial search functionality. This project is called Spatial4j (formerly Lucene Spatial Playground), and it works great, solving all known issues with the previous implementation.
What's even more great about it is it was built from the ground up to support complex searches, like polygons and other custom shapes, as well as different search strategies. This is not just about a circle and a radius anymore. The guys that created it really dig geo-spatial searches, so it is probably going to get a lot better over time.
This library as well as it's accompanying Lucene module are now part of Lucene, and should be available to all when Lucene 4.0 is released.
Since RavenDB uses the old spatial module, we were getting quite a few bug reports ourselves, without really being able to do anything about it. So when we heard about this project, it was clear that we should be using it. And since it is written in Java, well - luckily this isn't the first piece of Java code I've been porting...
The Spatial4n library - the .NET version of Spatial4j - is available here: https://github.com/synhershko/Spatial4n
The Lucene part of things, sync'd with Lucene.NET's trunk, can be found here: https://github.com/synhershko/lucene.net/tree/spatial2trunk . It will be there until those are merged upstream. There is also a branch with the new spatial module that is compatible with the 2.9.4 API - https://github.com/synhershko/lucene.net/tree/spatial.
We had to do some custom coding to get it to work with all the functionality we wanted, but it was all doable and so far this library looks very promising. All it needs now is a bit more attention.
November 14th, 2012 - 15:50
Hello! Do you have any link with some documentation when I can see how to do spatial searches with Spatial4net?
I’m just migrating to Lucene.net 3.0.3 and I’m quite lost.
Thanks!
November 14th, 2012 - 16:20
No docs, only the spatial contrib test suite and a small sample app I presented a few months back:
https://github.com/synhershko/Talks/tree/master/LuceneNeatThings/SpatialDemo
https://svn.apache.org/repos/asf/lucene.net/trunk/test/contrib/Spatial/
Also take a look at the other post here on RavenDB’s spatial implementation, it is based on S4n and therefore shares all the concepts
HTH
November 15th, 2012 - 12:22
Thanks for your answer.
I’ve been trying to implement it, but it seems there is no implementation for: IsWithin, just for Intersects
In lucene.net.3.0.3.contrib source there is:
public override Filter MakeFilter(SpatialArgs args)
{
var op = args.Operation;
if (op != SpatialOperation.Intersects)
throw new UnsupportedSpatialOperation(op);
Any idea?
November 15th, 2012 - 14:51
Please post a failing test to the Lucene.NET mailing list
November 29th, 2012 - 20:09
What’s the latest version of Spatial4n? On github, there appears to be version 1.0, but on nuget, it’s .03?
Thanks in advance.
November 30th, 2012 - 00:34
0.3 – it’s just the same as the one on github – https://github.com/synhershko/Spatial4n/tags