/* This example ignores exceptions. In practice, they must be thrown the enclosing function or caught with try/catch blocks. */ /* Creating the IndexWriter * / Analyzer analyzer = new EnglishAnalyzer(VERSION.Lucene_40); IndexWriterConfig config = new IndexWriterConfig(analyzer); Directory dir = FSDirectory.open(new File("/home/user/lucene/index")); IndexWriter writer = new IndexWriter(dir, config); /* The Document */ Field textField = new TextField("text", "Otto goes home.", Field.Store.YES); Document doc = new Document(); doc.add(textField); /* Add document to the index and save and close all files */ writer.addDocument(doc); writer.close();