2
0

Zend_Search_Lucene-JavaLucene.xml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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>
  5. <sect2 id="zend.search.lucene.index-creation.file-formats">
  6. <title>File Formats</title>
  7. <para>
  8. <classname>Zend_Search_Lucene</classname> index file formats are binary compatible with Java Lucene
  9. version 1.4 and greater.
  10. </para>
  11. <para>
  12. A detailed description of this format is available here:
  13. <ulink url="http://lucene.apache.org/java/docs/fileformats.html"/>
  14. <footnote><para>The currently supported Lucene index file format version is 2.3 (starting from ZF 1.6).</para></footnote>.
  15. </para>
  16. </sect2>
  17. <sect2 id="zend.search.lucene.index-creation.index-directory">
  18. <title>Index Directory</title>
  19. <para>
  20. After index creation, the index directory will contain several files:
  21. </para>
  22. <itemizedlist>
  23. <listitem>
  24. <para>
  25. The <filename>segments</filename> file is a list of index segments.
  26. </para>
  27. </listitem>
  28. <listitem>
  29. <para>
  30. The <filename>*.cfs</filename> files contain index segments.
  31. Note! An optimized index always has only one segment.
  32. </para>
  33. </listitem>
  34. <listitem>
  35. <para>
  36. The <filename>deletable</filename> file is a list of files that are no longer used
  37. by the index, but which could not be deleted.
  38. </para>
  39. </listitem>
  40. </itemizedlist>
  41. </sect2>
  42. <sect2 id="zend.search.lucene.java-lucene.source-code">
  43. <title>Java Source Code</title>
  44. <para>
  45. The Java program listing below provides an example of how to index a file
  46. using Java Lucene:
  47. </para>
  48. <programlisting language="java"><![CDATA[
  49. /**
  50. * Index creation:
  51. */
  52. import org.apache.lucene.index.IndexWriter;
  53. import org.apache.lucene.document.*;
  54. import java.io.*
  55. ...
  56. IndexWriter indexWriter = new IndexWriter("/data/my_index",
  57. new SimpleAnalyzer(), true);
  58. ...
  59. String filename = "/path/to/file-to-index.txt"
  60. File f = new File(filename);
  61. Document doc = new Document();
  62. doc.add(Field.Text("path", filename));
  63. doc.add(Field.Keyword("modified",DateField.timeToString(f.lastModified())));
  64. doc.add(Field.Text("author", "unknown"));
  65. FileInputStream is = new FileInputStream(f);
  66. Reader reader = new BufferedReader(new InputStreamReader(is));
  67. doc.add(Field.Text("contents", reader));
  68. indexWriter.addDocument(doc);
  69. ]]></programlisting>
  70. </sect2>
  71. </sect1>
  72. <!--
  73. vim:se ts=4 sw=4 et:
  74. -->