[MANUAL] English:
[zend.git] / documentation / manual / en / module_specs / Zend_Search_Lucene-JavaLucene.xml
blob59e5a303edab80efd25cb1600b3c583f0c1e0fa1
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!-- Reviewed: no -->
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>
9         <para>
10             <classname>Zend_Search_Lucene</classname> index file formats are binary compatible with
11             Java Lucene version 1.4 and greater.
12         </para>
14         <para>
15             A detailed description of this format is available here:
16             <ulink url="http://lucene.apache.org/java/2_3_0/fileformats.html"/>
17             <footnote>
18                 <para>
19                     The currently supported Lucene index file format version is 2.3 (starting from
20                     Zend Framework 1.6).
21                 </para>
22             </footnote>.
23         </para>
24     </sect2>
26     <sect2 id="zend.search.lucene.index-creation.index-directory">
27         <title>Index Directory</title>
29         <para>
30             After index creation, the index directory will contain several files:
31         </para>
33         <itemizedlist>
34             <listitem>
35                 <para>
36                     The <filename>segments</filename> file is a list of index segments.
37                 </para>
38             </listitem>
40             <listitem>
41                 <para>
42                     The <filename>*.cfs</filename> files contain index segments.
43                     Note! An optimized index always has only one segment.
44                 </para>
45             </listitem>
47             <listitem>
48                 <para>
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.
51                 </para>
52             </listitem>
53         </itemizedlist>
54     </sect2>
56     <sect2 id="zend.search.lucene.java-lucene.source-code">
57         <title>Java Source Code</title>
59         <para>
60             The Java program listing below provides an example of how to index a file
61             using Java Lucene:
62         </para>
64         <programlisting language="java"><![CDATA[
65 /**
66 * Index creation:
68 import org.apache.lucene.index.IndexWriter;
69 import org.apache.lucene.document.*;
71 import java.io.*
73 ...
75 IndexWriter indexWriter = new IndexWriter("/data/my_index",
76                                           new SimpleAnalyzer(), true);
78 ...
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);
92 ]]></programlisting>
93     </sect2>
94 </sect1>
95 <!--
96 vim:se ts=4 sw=4 et:
97 -->