Local Lucene

Local lucene is an effort to provide geographical search capibilities to Java Lucene.
Local lucene is not a search engine in itself but the libaries and capabilieties to create one, Lucene provides
the text searching capibilities and locallucene provides the geographical nature.

Locallucene is based on the white paper

Using local lucene

A good example of using local lucene is in src/com/pjaol/search/test/UnitTests/TestDistance.java

To begin with, the data has to be indexed, latitudes and longitudes
have to be converted to positive padded strings in order to be used with lucene.
By default lucene stores and searches Strings, so signed decimals have to be converted
to representative strings.

This is done by using Solr's number utils

private void addPoint(IndexWriter writer, String name, double lat, double lng) throws IOException{

Document doc = new Document();

doc.add(new Field("name", name,Field.Store.YES, Field.Index.TOKENIZED));

// convert the lat / long to lucene fields
doc.add(new Field(latField, NumberUtils.double2sortableStr(lat),Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.add(new Field(lngField, NumberUtils.double2sortableStr(lng),Field.Store.YES, Field.Index.UN_TOKENIZED));

// add a default meta field to make searching all documents easy
doc.add(new Field("metafile", "doc",Field.Store.YES, Field.Index.TOKENIZED));

int ctpsize = ctps.size();
for (int i =0; i < ctpsize; i++){
CartesianTierPlotter ctp = ctps.get(i);
doc.add(new Field(ctp.getTierFieldName(),


Searching can now be performed by using Custom Serial Filter, DistanceFilter and DistanceQuery

IndexSearcher searcher = new IndexSearcher(directory);

// reston va
double lat = 38.967446;
double lng= -77.360499;
String latField = "lat";
String lnfField ="lng";
final double miles = 6.0;

// create a distance query
DistanceQuery dq = new DistanceQuery(lat, lng, miles, latField, lngField, true);

//create a term query to search against all documents
Query tq = new TermQuery(new Term("metafile", "doc"));

// Create a distance sort
// As the radius filter has performed the distance calculations
// already, pass in the filter to reuse the results.

DistanceSortSource dsort = new DistanceSortSource(dq.distanceFilter);
Sort sort = new Sort(new SortField("foo", dsort));

// Perform the search, using the term query, the serial chain filter, and the
// distance sort

Hits hits = searcher.search(tq, dq.getFilter(),sort);

How the actual Cartesian Search is performed is documented at
http://www.nsshutdown.com /projects/lucene/whitepaper /locallucene_v2.html

An example of implementation of the locallucene library can be seen from com.pjaol.search.test.UnitTests.TestCartesian.java