lucene-indexing.xml 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="learning.lucene.indexing">
  4. <title>Indexing</title>
  5. <para>
  6. Indexing is performed by adding a new document to an existing or new index:
  7. </para>
  8. <programlisting language="php"><![CDATA[
  9. $index->addDocument($doc);
  10. ]]></programlisting>
  11. <para>
  12. There are two ways to create document object. The first is to do it manually.
  13. </para>
  14. <example id="learning.lucene.indexing.doc-creation">
  15. <title>Manual Document Construction</title>
  16. <programlisting language="php"><![CDATA[
  17. $doc = new Zend_Search_Lucene_Document();
  18. $doc->addField(Zend_Search_Lucene_Field::Text('url', $docUrl));
  19. $doc->addField(Zend_Search_Lucene_Field::Text('title', $docTitle));
  20. $doc->addField(Zend_Search_Lucene_Field::unStored('contents', $docBody));
  21. $doc->addField(Zend_Search_Lucene_Field::binary('avatar', $avatarData));
  22. ]]></programlisting>
  23. </example>
  24. <para>
  25. The second method is to load it from <acronym>HTML</acronym> or Microsoft Office 2007 files:
  26. </para>
  27. <example id="learning.lucene.indexing.doc-loading">
  28. <title>Document loading</title>
  29. <programlisting language="php"><![CDATA[
  30. $doc = Zend_Search_Lucene_Document_Html::loadHTML($htmlString);
  31. $doc = Zend_Search_Lucene_Document_Docx::loadDocxFile($path);
  32. $doc = Zend_Search_Lucene_Document_Pptx::loadPptFile($path);
  33. $doc = Zend_Search_Lucene_Document_Xlsx::loadXlsxFile($path);
  34. ]]></programlisting>
  35. </example>
  36. <para>
  37. If a document is loaded from one of the supported formats, it still can be extended manually
  38. with new user defined fields.
  39. </para>
  40. <sect2 id="learning.lucene.indexing.policy">
  41. <title>Indexing Policy</title>
  42. <para>
  43. You should define indexing policy within your application architectural design.
  44. </para>
  45. <para>
  46. You may need an on-demand indexing configuration (something like <acronym>OLTP</acronym>
  47. system). In such systems, you usually add one document per user request. As such, the
  48. <emphasis>MaxBufferedDocs</emphasis> option will not affect the system. On the other
  49. hand, <emphasis>MaxMergeDocs</emphasis> is really helpful as it allows you to limit
  50. maximum script execution time. <emphasis>MergeFactor</emphasis> should be set to a value
  51. that keeps balance between the average indexing time (it's also affected by average
  52. auto-optimization time) and search performance (index optimization level is dependent on
  53. the number of segments).
  54. </para>
  55. <para>
  56. If you will be primarily performing batch index updates, your configuration should use a
  57. <emphasis>MaxBufferedDocs</emphasis> option set to the maximum value supported by the
  58. available amount of memory. <emphasis>MaxMergeDocs</emphasis> and
  59. <emphasis>MergeFactor</emphasis> have to be set to values reducing auto-optimization
  60. involvement as much as possible <footnote><para>An additional limit is the maximum file
  61. handlers supported by the operation system for concurrent open
  62. operations</para></footnote>. Full index optimization should be applied after
  63. indexing.
  64. </para>
  65. <example id="learning.lucene.indexing.optimization">
  66. <title>Index optimization</title>
  67. <programlisting language="php"><![CDATA[
  68. $index->optimize();
  69. ]]></programlisting>
  70. </example>
  71. <para>
  72. In some configurations, it's more effective to serialize index updates by organizing
  73. update requests into a queue and processing several update requests in a single script
  74. execution. This reduces index opening overhead, and allows utilizing index document
  75. buffering.
  76. </para>
  77. </sect2>
  78. </sect1>