lucene-index-structure.xml 4.6 KB

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