Correct indexing of latitude and longitude values ​​in Lucene

I’m working on the function “Nearest City Search within a given radius” using the Lucene API. Index city armor and long values ​​in Lucene as follows:

doc.Add(new Field("latitude", paddedLatitude, Field.Store.YES, Field.Index.UN_TOKENIZED));

doc.Add(new Field("longitude", paddedLongitude, Field.Store.YES, Field.Index.UN_TOKENIZED));

Since Lucene only understands strings, not numbers, am padding lat and long values.

For example, if the original long and long 41.811846 and -87.820628, respectively, after filling the values ​​look like this:

paddedLatitude → "0041.811846" and paddedLongitude → "- 087.820628"

I’m doing the same addition, creating the nearest city query (using the Lucene ConstantScoreRangeQuery class).

Given the fact that the lat and long values ​​can be decimal / negative numbers, is this the right approach to index them so that I can get the correct nearest cities in the search results when lucene performed a series of Range / Compare operations on these values?

Thanks.

+5
source share
2 answers

Here's a bleeding edge about Searching for Number Fields in Lucene by expert on the subject Uwe Schindler. You may need to use the older (and slower) ConstantScoreRangeQuery because Lucene.net is slightly behind Lucene and the NumericRangeQuery class described in the link has not yet been released in Java Lucene.

+6
source

Yuval F , , , , .

, , , .

, , . , , , , , , , .

, , , - , .

+1

All Articles