1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.search.lucene.java-lucene">
4 <title>Interoperating with Java Lucene</title>
6 <sect2 id="zend.search.lucene.index-creation.file-formats">
7 <title>File Formats</title>
10 <classname>Zend_Search_Lucene</classname> index file formats are binary compatible with
11 Java Lucene version 1.4 and greater.
15 A detailed description of this format is available here:
16 <ulink url="http://lucene.apache.org/java/2_3_0/fileformats.html"/>
19 The currently supported Lucene index file format version is 2.3 (starting from
26 <sect2 id="zend.search.lucene.index-creation.index-directory">
27 <title>Index Directory</title>
30 After index creation, the index directory will contain several files:
36 The <filename>segments</filename> file is a list of index segments.
42 The <filename>*.cfs</filename> files contain index segments.
43 Note! An optimized index always has only one segment.
49 The <filename>deletable</filename> file is a list of files that are no longer
50 used by the index, but which could not be deleted.
56 <sect2 id="zend.search.lucene.java-lucene.source-code">
57 <title>Java Source Code</title>
60 The Java program listing below provides an example of how to index a file
64 <programlisting language="java"><![CDATA[
68 import org.apache.lucene.index.IndexWriter;
69 import org.apache.lucene.document.*;
75 IndexWriter indexWriter = new IndexWriter("/data/my_index",
76 new SimpleAnalyzer(), true);
80 String filename = "/path/to/file-to-index.txt"
81 File f = new File(filename);
83 Document doc = new Document();
84 doc.add(Field.Text("path", filename));
85 doc.add(Field.Keyword("modified",DateField.timeToString(f.lastModified())));
86 doc.add(Field.Text("author", "unknown"));
87 FileInputStream is = new FileInputStream(f);
88 Reader reader = new BufferedReader(new InputStreamReader(is));
89 doc.add(Field.Text("contents", reader));
91 indexWriter.addDocument(doc);