Zend_Search_Lucene-Overview.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <sect1 id="zend.search.lucene.overview">
  2. <title>概述</title>
  3. <sect2 id="zend.search.lucene.introduction">
  4. <title>简介</title>
  5. <para>
  6. Zend_Search_Lucene 是一个完全由 PHP 5 编写的通用文本搜索引擎。由于其将索引保存在文件系统中而不需要数据库支持,因此它几乎可以为任何由 PHP 驱动的网站增加搜索能力。Zend_Search_Lucene 支持下列特性:
  7. <itemizedlist>
  8. <listitem>
  9. <para>具有排名功能的搜索——最符合要求的结果出现在最前面</para>
  10. </listitem>
  11. <listitem>
  12. <para>
  13. 许多强大的查询类型:短语查询、通配符查询、近似查询、范围查询等
  14. <footnote>
  15. <para>
  16. 目前只支持单项和多项查询。
  17. </para>
  18. </footnote>
  19. </para>
  20. </listitem>
  21. <listitem>
  22. <para>搜索特定的字段,如标题、作者、内容,等等</para>
  23. </listitem>
  24. </itemizedlist>
  25. Zend_Search_Lucene 来源于 Apache Lucene project。要了解关于 Lucene 的更多详情,请访问
  26. <ulink url="http://lucene.apache.org/java/docs/"/>。
  27. </para>
  28. </sect2>
  29. <sect2 id="zend.search.lucene.index-creation.documents-and-fields">
  30. <title>文档和字段对象</title>
  31. <para>
  32. Zend_Search_Lucene 把文档最为基本的索引主题。而文档(document)又分为若干被命名的字段(field),字段中包含可供搜索的内容。
  33. </para>
  34. <para>
  35. 一个文档被表现为 Zend_Search_Lucene_Document 对象,这个对象包含了若干 Zend_Search_Lucene_Field 对象,用以表现相应的字段。
  36. </para>
  37. <para>
  38. 需要特别说明的是任意类型的信息都可以被加入索引中。应用程序描述信息或者元信息(metadata)可以被保存在文档字段中,并在搜索过程中与文档一起被检索。
  39. </para>
  40. <para>
  41. 控制这些索引是你的应用程序的责任。这意味着任意你的应用程序可以访问的数据来源都可以进行索引。例如,这些数据可以来自于文件系统、数据库或者是 HTML 表单,等等。
  42. </para>
  43. <para>
  44. <code>Zend_Search_Lucene_Field</code> 类提供了一些静态方法用以创建具有不同特点的字段:
  45. </para>
  46. <programlisting role="php"><![CDATA[<?php
  47. $doc = new Zend_Search_Lucene_Document();
  48. // Field is not tokenized, but is indexed and stored within the index.
  49. // Stored fields can be retrived from the index.
  50. $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype',
  51. 'autogenerated'));
  52. // Field is not tokenized nor indexed, but is stored in the index.
  53. $doc->addField(Zend_Search_Lucene_Field::UnIndexed('created',
  54. time()));
  55. // Binary String valued Field that is not tokenized nor indexed,
  56. // but is stored in the index.
  57. $doc->addField(Zend_Search_Lucene_Field::Binary('icon',
  58. $iconData));
  59. // Field is tokenized and indexed, and is stored in the index.
  60. $doc->addField(Zend_Search_Lucene_Field::Text('annotation',
  61. 'Document annotation text'));
  62. // Field is tokenized and indexed, but that is not stored in the index.
  63. $doc->addField(Zend_Search_Lucene_Field::UnStored('contents',
  64. 'My document content'));
  65. ?>]]></programlisting>
  66. <para>
  67. 你可以按照自己的需要给字段命名。名为“contents”的字段缺省的用于搜索。因此,将主要的文档内容放在这个字段中会是个好主意。
  68. </para>
  69. </sect2>
  70. <sect2 id="zend.search.lucene.index-creation.understanding-field-types">
  71. <title>理解字段类型</title>
  72. <itemizedlist>
  73. <listitem>
  74. <para>
  75. <code>Keyword</code> 关键词字段是被保存和被索引的,意思是它们既可以被搜索,也可以在搜索结果中被显示。它们并没有以记号化的方式拆分为多个不同的词。在 Zend_Search_Lucene 中,枚举形的数据库字段通常可以很好的转化为关键词字段。
  76. </para>
  77. </listitem>
  78. <listitem>
  79. <para>
  80. <code>UnIndexed</code> 不索引字段是不可搜索的,但是它们会在搜索结果中返回用于生成点击信息。数据库的时间戳、主键、文件系统的路径、以及其它标识是不索引字段的好的候选人。
  81. </para>
  82. </listitem>
  83. <listitem>
  84. <para>
  85. <code>Binary</code> 二进制字段是不记号化和不被索引的,但是被保存以供生成点击信息。它们可以用于保存任何以二进制方式编码的信息,例如图标等等。
  86. </para>
  87. </listitem>
  88. <listitem>
  89. <para>
  90. <code>Text</code> 文本字段是被保存的、被索引的和记号化的。文本字段适合用于保存像是主题、标题这样既能被搜索又能作为搜索结果返回的信息。
  91. </para>
  92. </listitem>
  93. <listitem>
  94. <para>
  95. <code>UnStored</code> 不保存字段是记号化和被索引的,但并不保存在索引中。大量的文本信息最好使用这种字段类型。保存的数据在硬盘上创建了大量的索引,如果你需要搜索而不需要在搜索结果中显示这些数据,就使用不保存字段。当结合使用 Zend_Search_Lucene 索引和关系数据库时最适合使用不保存字段。你通过不保存字段索引大量数据用于搜索,并通过作为标识的特定字段从你的关系数据库中获取它们。
  96. </para>
  97. <table>
  98. <title>Zend_Search_Lucene_Field 类型</title>
  99. <tgroup cols="5">
  100. <thead>
  101. <row>
  102. <entry>字段类型</entry>
  103. <entry>保存</entry>
  104. <entry>索引</entry>
  105. <entry>记号化</entry>
  106. <entry>二进制</entry>
  107. </row>
  108. </thead>
  109. <tbody>
  110. <row>
  111. <entry>Keyword</entry>
  112. <entry>是</entry>
  113. <entry>是</entry>
  114. <entry>否</entry>
  115. <entry>否</entry>
  116. </row>
  117. <row>
  118. <entry>UnIndexed</entry>
  119. <entry>是</entry>
  120. <entry>否</entry>
  121. <entry>否</entry>
  122. <entry>否</entry>
  123. </row>
  124. <row>
  125. <entry>Binary</entry>
  126. <entry>是</entry>
  127. <entry>否</entry>
  128. <entry>否</entry>
  129. <entry>是</entry>
  130. </row>
  131. <row>
  132. <entry>Text</entry>
  133. <entry>是</entry>
  134. <entry>是</entry>
  135. <entry>是</entry>
  136. <entry>否</entry>
  137. </row>
  138. <row>
  139. <entry>UnStored</entry>
  140. <entry>否</entry>
  141. <entry>是</entry>
  142. <entry>是</entry>
  143. <entry>否</entry>
  144. </row>
  145. </tbody>
  146. </tgroup>
  147. </table>
  148. </listitem>
  149. </itemizedlist>
  150. </sect2>
  151. </sect1>
  152. <!--
  153. vim:se ts=4 sw=4 et:
  154. -->