lucene-index-structure.xml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19766 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="learning.lucene.index-structure">
  5. <title>Lucene Index Structure</title>
  6. <para>
  7. In order to fully utilize <classname>Zend_Search_Lucene</classname>'s capabilities with
  8. maximum performance, you need to understand it's internal index structure.
  9. </para>
  10. <para>
  11. An <emphasis>index</emphasis> is stored as a set of files within a single directory.
  12. </para>
  13. <para>
  14. An <emphasis>index</emphasis> consists of any number of independent
  15. <emphasis>segments</emphasis> which store information about a subset of indexed documents.
  16. Each <emphasis>segment</emphasis> has its own <emphasis>terms dictionary</emphasis>, terms
  17. dictionary index, and document storage (stored field values) <footnote><para>Starting with
  18. Lucene 2.3, document storage files can be shared between segments; however,
  19. <classname>Zend_Search_Lucene</classname> doesn't use this
  20. capability</para></footnote>. All segment data is stored in
  21. <filename>_xxxxx.cfs</filename> files, where <emphasis>xxxxx</emphasis> is a segment name.
  22. </para>
  23. <para>
  24. Once an index segment file is created, it can't be updated. New documents are added to new
  25. segments. Deleted documents are only marked as deleted in an optional
  26. <filename>&lt;segmentname&gt;.del</filename> file.
  27. </para>
  28. <para>
  29. Document updating is performed as separate delete and add operations, even though it's done
  30. using an <methodname>update()</methodname> <acronym>API</acronym> call
  31. <footnote><para>This call is provided only by Java Lucene now, but it's planned to extend
  32. the <classname>Zend_Search_Lucene</classname> <acronym>API</acronym> with similar
  33. functionality</para></footnote>.
  34. This simplifies adding new documents, and allows updating concurrently with search
  35. operations.
  36. </para>
  37. <para>
  38. On the other hand, using several segments (one document per segment as a borderline case)
  39. increases search time:
  40. </para>
  41. <itemizedlist>
  42. <listitem>
  43. <para>
  44. retrieving a term from a dictionary is performed for each segment;
  45. </para>
  46. </listitem>
  47. <listitem>
  48. <para>
  49. the terms dictionary index is pre-loaded for each segment (this process takes the
  50. most search time for simple queries, and it also requires additional memory).
  51. </para>
  52. </listitem>
  53. </itemizedlist>
  54. <para>
  55. If the terms dictionary reaches a saturation point, then search through one segment is
  56. <emphasis>N</emphasis> times faster than search through <emphasis>N</emphasis> segments
  57. in most cases.
  58. </para>
  59. <para>
  60. <emphasis>Index optimization</emphasis> merges two or more segments into a single new one. A
  61. new segment is added to the index segments list, and old segments are excluded.
  62. </para>
  63. <para>
  64. Segment list updates are performed as an atomic operation. This gives the ability of
  65. concurrently adding new documents, performing index optimization, and searching through the
  66. index.
  67. </para>
  68. <para>
  69. Index auto-optimization is performed after each new segment generation. It merges sets of
  70. the smallest segments into larger segments, and larger segments into even larger segments,
  71. if we have enough segments to merge.
  72. </para>
  73. <para>
  74. Index auto-optimization is controlled by three options:
  75. </para>
  76. <itemizedlist>
  77. <listitem>
  78. <para>
  79. <emphasis>MaxBufferedDocs</emphasis> (the minimal number of documents required
  80. before the buffered in-memory documents are written into a new segment);
  81. </para>
  82. </listitem>
  83. <listitem>
  84. <para>
  85. <emphasis>MaxMergeDocs</emphasis> (the largest number of documents ever merged by
  86. an optimization operation); and
  87. </para>
  88. </listitem>
  89. <listitem>
  90. <para>
  91. <emphasis>MergeFactor</emphasis> (which determines how often segment indices are
  92. merged by auto-optimization operations).
  93. </para>
  94. </listitem>
  95. </itemizedlist>
  96. <para>
  97. If we add one document per script execution, then <emphasis>MaxBufferedDocs</emphasis> is
  98. actually not used (only one new segment with only one document is created at the end of
  99. script execution, at which time the auto-optimization process starts).
  100. </para>
  101. </sect1>