Search code examples
c#search-enginelucene.netspatial

Inconsistent search results using spatial.net and lucene.net 2.9


Hello I am currently working on implementing a spatial search feature for a website using c#, lucene.net and spatial.net

The issue I am running into is the following:

I index 5 document with the following locations:
Document 1: Los Angeles, CA
Document 2: Pasadena, CA
Document 3: Santa Monica, CA
Document 4: Sacramento, CA
Document 5: Denver, CO

Then I proceed to run several searches on the resulting index (for my NUnit test I am using RAMDirectory) using the Los Angeles point as origin, as well as having it be a part of the data.

Radius Results Pass
10 Miles 1 Yes
20 Miles 2 No
25 Miles 2 No
50 Miles 3 Yes

Note that I expeted 3 results beginnig with the 20 mile search. This also happens with some other radius values, for example 5000 miles return only 1 result when at 3500 miles I was getting all 5 documents.

Is anyone aware of a bug in the spatial.net code that could be causing this? The .net version of lucene is at 2.9.2 and perhaps this has been addressed in a later version. Any help would be appreciated, thanks


Solution

  • I finally got this working. There is a bug on the spatial.net contrib module in the current version of lucene.net
    This bug makes the search fail in some edge cases. The issue is caused by the CartesianShapeFilter class. What I did was grab the source from the Java version of lucene and port only the spatial contrib code.
    After every class was ported I would compile and run my test again. Finally I narrowed it down to this class.
    I hope this helps someone, if you would like the code for this I will be sending a patch to the folks working on lucene.net so the can make it available.