Skip to content

Instantly share code, notes, and snippets.

@janakact
Last active October 20, 2016 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janakact/a2de8a4d3edc26e721228992eeef5b80 to your computer and use it in GitHub Desktop.
Save janakact/a2de8a4d3edc26e721228992eeef5b80 to your computer and use it in GitHub Desktop.
Initialize the index writer and index data.
// --------------------------------------------------------------------------------
//Initiate the writer -------------------------------------------------------------
writer = new IndexWriter(indexDir, new IndexWriterConfig(
new WhitespaceAnalyzer()).setOpenMode(IndexWriterConfig.OpenMode.CREATE));
//Index Data ----------------------------------------------------------------------
//Sample Data 1 -------------------------------------------------------------------
Document doc = new Document();
doc.add(new StoredField(NAME_TAG ,"Colombo Ratmalana")); //Stored fields will be stored in the index and values can be retrieved from the index
doc.add(new StoredField(CITY_TAG,"Colombo"));
//Index data as a LatLon Point
doc.add(new LatLonPoint(LOCATION_TAG, 6.821994,79.886208));
//Index Altitude as a FloatPoint. An One-Dimensional Point
doc.add(new FloatPoint(ALT_TAG,22));
//Write the document into Index
writer.addDocument(doc);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment