我在互联网上搜索了很多信息,也尝试了很多不同的建议,但似乎没有什么能满足我的需要。所以这就是问题所在:我想使用 Zend_Search_Lucene 在数据库中执行搜索,但我一开始就卡住了.. 创建索引并让 Zend 工作。我在共享 Hostgator 主机上并使用此 php 代码生成我的索引:
include ('/home/username/public_html/website/config.php');
$path = '/usr/local/Zend';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once('Zend/Loader.php');
Zend_Loader::registerAutoload();
require_once ('Zend/Search/Lucene.php');
$index = Zend_Search_Lucene::create('/home/username/public_html/website/tmpbuild');
$con = mysql_connect("".$dbhost."","".$dbusername."","".$dbpass."");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("".$dbname."", $con);
$sql = ('SELECT * FROM rasti_failai');
while($eilute = mysql_fetch_array($sql))
{
$filenamesql = $eilute['failu_name'];
$dydissql = $eilute['dydis'];
$hostas = $eilute['hostas'];
$datasql = $eilute['data'];
$aprasymassql = $eilute['header'];
$titlesql = $eilute['aprasymas'];
$url = $eilute['url'];
$links = $eilute['links'];
$document = new Zend_Search_Lucene_Document ();
$document->addField(Zend_Search_Lucene_Field::unIndexed('ID', $eilute['ID']));
$document->addField(Zend_Search_Lucene_Field::Text('failu_name', $eilute['failu_name']));
$document->addField(Zend_Search_Lucene_Field::UnStored('dydis', $eilute['dydis']));
$document->addField(Zend_Search_Lucene_Field::UnStored('hostas', $eilute['hostas']));
$document->addField(Zend_Search_Lucene_Field::UnStored('header', $eilute['header']));
$document->addField(Zend_Search_Lucene_Field::UnStored('aprasymas', $eilute['aprasymas']));
$document->addField(Zend_Search_Lucene_Field::UnStored('url', $eilute['url']));
$index->addDocument($document); }
$index->commit();
echo $index->count() . " documents have been indexed.\n";
但似乎我无法让 Zend 框架工作,因为我收到了这个错误:
Warning: require_once(Zend/Loader.php) [function.require-once]: failed to open stream: No such file or directory in /home/username/public_html/website/adminp/lucene.php on line 15
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Loader.php' (include_path='.:/usr/lib/php:/usr/local/lib/php:/usr/local/Zend') in /home/username/public_html/website/adminp/lucene.php on line 15
我的主机安装了 zend 框架(虽然我不知道确切的版本,但我认为 hostgator 使用的是最新的,而我使用的是 php5),并且支持说它在 /usr/local/Zend 目录中。