<?xml version="1.0" encoding="UTF-8"?>
<!-- Reviewed: no -->
<sect1 id="zend.search.lucene.java-lucene">
    <title>Interoperating with Java Lucene</title>

    <sect2 id="zend.search.lucene.index-creation.file-formats">
        <title>File Formats</title>
        <para>
          <classname>Zend_Search_Lucene</classname> index file formats are binary compatible with Java Lucene
          version 1.4 and greater.
        </para>

        <para>
          A detailed description of this format is available here:
          <ulink url="http://lucene.apache.org/java/docs/fileformats.html"/>
          <footnote><para>The currently supported Lucene index file format version is 2.3 (starting from ZF 1.6).</para></footnote>.
        </para>
    </sect2>

    <sect2 id="zend.search.lucene.index-creation.index-directory">
        <title>Index Directory</title>

        <para>
        After index creation, the index directory will contain several files:
        </para>

        <itemizedlist>
            <listitem>
                <para>
                The <filename>segments</filename> file is a list of index segments.
                </para>
            </listitem>
            <listitem>
                <para>
                The <filename>*.cfs</filename> files contain index segments.
                Note! An optimized index always has only one segment.
                </para>
            </listitem>
            <listitem>
                <para>
                The <filename>deletable</filename> file is a list of files that are no longer used
                by the index, but which could not be deleted.
                </para>
            </listitem>
        </itemizedlist>
    </sect2>

    <sect2 id="zend.search.lucene.java-lucene.source-code">
        <title>Java Source Code</title>
        <para>
            The Java program listing below provides an example of how to index a file
            using Java Lucene:
        </para>

        <programlisting language="java"><![CDATA[
/**
* Index creation:
*/
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.document.*;

import java.io.*

...

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.Keyword("modified",DateField.timeToString(f.lastModified())));
doc.add(Field.Text("author", "unknown"));
FileInputStream is = new FileInputStream(f);
Reader reader = new BufferedReader(new InputStreamReader(is));
doc.add(Field.Text("contents", reader));

indexWriter.addDocument(doc);
]]></programlisting>
    </sect2>
</sect1>

<!--
vim:se ts=4 sw=4 et:
-->
