Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Java Source Code

The Java program listing below provides an example of how to index a file using Java Lucene:

* Index creation:
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.*;



IndexWriter indexWriter = new IndexWriter("/data/my_index",
                                          new SimpleAnalyzer(), true);


String filename = "/path/to/file-to-index.txt"
File f = new File(filename);

Document doc = new Document();
doc.add(Field.Text("path", filename));
doc.add(Field.Text("author", "unknown"));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text("contents", reader));


Zend Framework