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.
source
share