lucene-intro.xml 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="learning.lucene.intro">
  4. <title>Zend_Search_Lucene Introduction</title>
  5. <para>
  6. The <classname>Zend_Search_Lucene</classname> component is intended to provide a
  7. ready-for-use full-text search solution. It doesn't require any <acronym>PHP</acronym>
  8. extensions<footnote><para>Though some <acronym>UTF-8</acronym> processing functionality
  9. requires the <emphasis>mbstring</emphasis> extension to be turned
  10. on</para></footnote> or additional software to be installed, and can be used
  11. immediately after Zend Framework installation.
  12. </para>
  13. <para>
  14. <classname>Zend_Search_Lucene</classname> is a pure <acronym>PHP</acronym> port of the
  15. popular open source full-text search engine known as Apache Lucene. See <ulink
  16. url="http://lucene.apache.org">http://lucene.apache.org/</ulink> for the details.
  17. </para>
  18. <para>
  19. Information must be indexed to be available for searching.
  20. <classname>Zend_Search_Lucene</classname> and Java Lucene use a document concept known as an
  21. "atomic indexing item."
  22. </para>
  23. <para>
  24. Each document is a set of fields: &lt;name, value&gt; pairs where name and value are
  25. <acronym>UTF-8</acronym> strings<footnote><para>Binary strings are also allowed to be used
  26. as field values</para></footnote>. Any subset of the document fields may be marked
  27. as "indexed" to include field data in the text indexing process.
  28. </para>
  29. <para>
  30. Field values may or may not be tokenized while indexing. If a field is not tokenized, then
  31. the field value is stored as one term; otherwise, the current analyzer is used for
  32. tokenization.
  33. </para>
  34. <para>
  35. Several analyzers are provided within the <classname>Zend_Search_Lucene</classname> package.
  36. The default analyzer works with <acronym>ASCII</acronym> text (since the
  37. <acronym>UTF-8</acronym> analyzer needs the <emphasis>mbstring</emphasis> extension to be
  38. turned on). It is case insensitive, and it skips numbers. Use other analyzers or create your
  39. own analyzer if you need to change this behavior.
  40. </para>
  41. <note>
  42. <title>Using analyzers during indexing and searching</title>
  43. <para>
  44. Important note! Search queries are also tokenized using the "current analyzer", so the
  45. same analyzer must be set as the default during both the indexing and searching process.
  46. This will guarantee that source and searched text will be transformed into terms in the
  47. same way.
  48. </para>
  49. </note>
  50. <para>
  51. Field values are optionally stored within an index. This allows the original field data to
  52. be retrieved from the index while searching. This is the only way to associate search
  53. results with the original data (internal document IDs may be changed after index
  54. optimization or auto-optimization).
  55. </para>
  56. <para>
  57. The thing that should be remembered is that a Lucene index is not a database. It doesn't
  58. provide index backup mechanisms except backup of the file system directory. It doesn't
  59. provide transactional mechanisms though concurrent index update as well as concurrent update
  60. and read are supported. It doesn't compare with databases in data retrieving speed.
  61. </para>
  62. <para>
  63. So it's good idea:
  64. </para>
  65. <itemizedlist>
  66. <listitem>
  67. <para>
  68. <emphasis>Not</emphasis> to use Lucene index as a storage since it may dramatically
  69. decrease search hit retrieving performance. Store only unique document identifiers
  70. (doc paths, <acronym>URL</acronym>s, database unique IDs) and associated data within
  71. an index. E.g. title, annotation, category, language info, avatar. (Note: a field
  72. may be included in indexing, but not stored, or stored, but not indexed).
  73. </para>
  74. </listitem>
  75. <listitem>
  76. <para>
  77. To write functionality that can rebuild an index completely if it's corrupted for
  78. any reason.
  79. </para>
  80. </listitem>
  81. </itemizedlist>
  82. <para>
  83. Individual documents in the index may have completely different sets of fields. The same
  84. fields in different documents don't need to have the same attributes. E.g. a field may be
  85. indexed for one document and skipped from indexing for another. The same applies for
  86. storing, tokenizing, or treating field value as a binary string.
  87. </para>
  88. </sect1>