| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <sect1 id="zend.search.lucene.overview">
- <title>概述</title>
- <sect2 id="zend.search.lucene.introduction">
- <title>简介</title>
- <para>
- Zend_Search_Lucene 是一个完全由 PHP 5 编写的通用文本搜索引擎。由于其将索引保存在文件系统中而不需要数据库支持,因此它几乎可以为任何由 PHP 驱动的网站增加搜索能力。Zend_Search_Lucene 支持下列特性:
- <itemizedlist>
- <listitem>
- <para>具有排名功能的搜索——最符合要求的结果出现在最前面</para>
- </listitem>
- <listitem>
- <para>
- 许多强大的查询类型:短语查询、通配符查询、近似查询、范围查询等
- <footnote>
- <para>
- 目前只支持单项和多项查询。
- </para>
- </footnote>
- </para>
- </listitem>
- <listitem>
- <para>搜索特定的字段,如标题、作者、内容,等等</para>
- </listitem>
- </itemizedlist>
- Zend_Search_Lucene 来源于 Apache Lucene project。要了解关于 Lucene 的更多详情,请访问
- <ulink url="http://lucene.apache.org/java/docs/"/>。
- </para>
- </sect2>
- <sect2 id="zend.search.lucene.index-creation.documents-and-fields">
- <title>文档和字段对象</title>
- <para>
- Zend_Search_Lucene 把文档最为基本的索引主题。而文档(document)又分为若干被命名的字段(field),字段中包含可供搜索的内容。
- </para>
- <para>
- 一个文档被表现为 Zend_Search_Lucene_Document 对象,这个对象包含了若干 Zend_Search_Lucene_Field 对象,用以表现相应的字段。
- </para>
- <para>
- 需要特别说明的是任意类型的信息都可以被加入索引中。应用程序描述信息或者元信息(metadata)可以被保存在文档字段中,并在搜索过程中与文档一起被检索。
- </para>
- <para>
- 控制这些索引是你的应用程序的责任。这意味着任意你的应用程序可以访问的数据来源都可以进行索引。例如,这些数据可以来自于文件系统、数据库或者是 HTML 表单,等等。
- </para>
- <para>
- <code>Zend_Search_Lucene_Field</code> 类提供了一些静态方法用以创建具有不同特点的字段:
- </para>
- <programlisting role="php"><![CDATA[<?php
- $doc = new Zend_Search_Lucene_Document();
- // Field is not tokenized, but is indexed and stored within the index.
- // Stored fields can be retrived from the index.
- $doc->addField(Zend_Search_Lucene_Field::Keyword('doctype',
- 'autogenerated'));
- // Field is not tokenized nor indexed, but is stored in the index.
- $doc->addField(Zend_Search_Lucene_Field::UnIndexed('created',
- time()));
- // Binary String valued Field that is not tokenized nor indexed,
- // but is stored in the index.
- $doc->addField(Zend_Search_Lucene_Field::Binary('icon',
- $iconData));
- // Field is tokenized and indexed, and is stored in the index.
- $doc->addField(Zend_Search_Lucene_Field::Text('annotation',
- 'Document annotation text'));
- // Field is tokenized and indexed, but that is not stored in the index.
- $doc->addField(Zend_Search_Lucene_Field::UnStored('contents',
- 'My document content'));
- ?>]]></programlisting>
- <para>
- 你可以按照自己的需要给字段命名。名为“contents”的字段缺省的用于搜索。因此,将主要的文档内容放在这个字段中会是个好主意。
- </para>
- </sect2>
- <sect2 id="zend.search.lucene.index-creation.understanding-field-types">
- <title>理解字段类型</title>
- <itemizedlist>
- <listitem>
- <para>
- <code>Keyword</code> 关键词字段是被保存和被索引的,意思是它们既可以被搜索,也可以在搜索结果中被显示。它们并没有以记号化的方式拆分为多个不同的词。在 Zend_Search_Lucene 中,枚举形的数据库字段通常可以很好的转化为关键词字段。
- </para>
- </listitem>
- <listitem>
- <para>
- <code>UnIndexed</code> 不索引字段是不可搜索的,但是它们会在搜索结果中返回用于生成点击信息。数据库的时间戳、主键、文件系统的路径、以及其它标识是不索引字段的好的候选人。
- </para>
- </listitem>
- <listitem>
- <para>
- <code>Binary</code> 二进制字段是不记号化和不被索引的,但是被保存以供生成点击信息。它们可以用于保存任何以二进制方式编码的信息,例如图标等等。
- </para>
- </listitem>
- <listitem>
- <para>
- <code>Text</code> 文本字段是被保存的、被索引的和记号化的。文本字段适合用于保存像是主题、标题这样既能被搜索又能作为搜索结果返回的信息。
- </para>
- </listitem>
- <listitem>
- <para>
- <code>UnStored</code> 不保存字段是记号化和被索引的,但并不保存在索引中。大量的文本信息最好使用这种字段类型。保存的数据在硬盘上创建了大量的索引,如果你需要搜索而不需要在搜索结果中显示这些数据,就使用不保存字段。当结合使用 Zend_Search_Lucene 索引和关系数据库时最适合使用不保存字段。你通过不保存字段索引大量数据用于搜索,并通过作为标识的特定字段从你的关系数据库中获取它们。
- </para>
- <table>
- <title>Zend_Search_Lucene_Field 类型</title>
- <tgroup cols="5">
- <thead>
- <row>
- <entry>字段类型</entry>
- <entry>保存</entry>
- <entry>索引</entry>
- <entry>记号化</entry>
- <entry>二进制</entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>Keyword</entry>
- <entry>是</entry>
- <entry>是</entry>
- <entry>否</entry>
- <entry>否</entry>
- </row>
- <row>
- <entry>UnIndexed</entry>
- <entry>是</entry>
- <entry>否</entry>
- <entry>否</entry>
- <entry>否</entry>
- </row>
- <row>
- <entry>Binary</entry>
- <entry>是</entry>
- <entry>否</entry>
- <entry>否</entry>
- <entry>是</entry>
- </row>
- <row>
- <entry>Text</entry>
- <entry>是</entry>
- <entry>是</entry>
- <entry>是</entry>
- <entry>否</entry>
- </row>
- <row>
- <entry>UnStored</entry>
- <entry>否</entry>
- <entry>是</entry>
- <entry>是</entry>
- <entry>否</entry>
- </row>
- </tbody>
- </tgroup>
- </table>
- </listitem>
- </itemizedlist>
- </sect2>
- </sect1>
- <!--
- vim:se ts=4 sw=4 et:
- -->
|