概述简介Zend_Search_Lucene 是一个完全由 PHP 5 编写的通用文本搜索引擎。由于其将索引保存在文件系统中而不需要数据库支持,因此它几乎可以为任何由 PHP 驱动的网站增加搜索能力。Zend_Search_Lucene 支持下列特性:
文档和字段对象Zend_Search_Lucene 把文档最为基本的索引主题。而文档(document)又分为若干被命名的字段(field),字段中包含可供搜索的内容。 一个文档被表现为 Zend_Search_Lucene_Document 对象,这个对象包含了若干 Zend_Search_Lucene_Field 对象,用以表现相应的字段。 需要特别说明的是任意类型的信息都可以被加入索引中。应用程序描述信息或者元信息(metadata)可以被保存在文档字段中,并在搜索过程中与文档一起被检索。 控制这些索引是你的应用程序的责任。这意味着任意你的应用程序可以访问的数据来源都可以进行索引。例如,这些数据可以来自于文件系统、数据库或者是 HTML 表单,等等。
<?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'));
?>你可以按照自己的需要给字段命名。名为“contents”的字段缺省的用于搜索。因此,将主要的文档内容放在这个字段中会是个好主意。 理解字段类型
[1]
目前只支持单项和多项查询。
|