用一个例子来说明如何在一个Yii application从Zend framework使用Zend_Search_Lucene部件。
首先,假设protected
是application base directory,我们提取Zend Framework的发布文件到protected/vendors
目录 。 确认protected/vendors/Zend/Search/Lucene.php
文件存在。
第二,在一个controller类文件的开始,加入以下行:
[php]
Yii::import('application.vendors.*');
require_once('Zend/Search/Lucene.php');
上述代码包含类文件Lucene.php
。因为我们使用的是相对路径,我们需要改变PHP的包含路径,以使文件可以正确定位。这是通过在require_once
之前调用Yii::import
做到。
一旦上述设立准备就绪后,我们可以在controller action里使用Lucene
类,类似如下:
[php]
$lucene=new Zend_Search_Lucene($pathOfIndex);
$hits=$lucene->find(strtolower($keyword));