我正在构建索引搜索。我像这样打开索引:
$index = Zend_Search_Lucene::open(ROOT_PATH.'/lucene/jedinice');
$index_elements = Zend_Search_Lucene::open(ROOT_PATH.'/lucene/elementi');
我的其余代码如下:
$obj = new stdClass();
$frontendOptions = array(
'lifetime' => 7200, // Cache lifetime of 2 hours
'automatic_serialization' => true
);
$backendOptions = array(
'cache_dir' => ROOT_PATH.'cache/services' // Directory where to put the cache files
);
// Getting a Zend_Cache_Core object
$cache = Zend_Cache::factory(
'Core','File', $frontendOptions, $backendOptions
);
$cacheId = md5($criteria->search_term);
$resultSet = array();
if (! $resultSet = $cache->load($cacheId))
{
$hits = $index->find($criteria->search_term);
$hits_elements = $index_elements->find($criteria->search_term, 'ElementKaoTekst');
fwrite($debug_file, serialize($hits) ."\n");
fwrite($debug_file, serialize($hits_elements) ."\n");
if ($hits)
{
foreach ($hits as $hit) {
$resultSetEntry = array();
$resultSetEntry['ID'] = $hit->ID;
$resultSetEntry['Naziv'] = $hit->Naziv;
$resultSetEntry['UIDJedinica'] = $hit->UID;
$resultSetEntry['UIDElement'] = '';
$resultSetEntry['Type'] = $hit->Type;
$resultSetEntry['IDElementTip'] = 0;
$resultSetEntry['KratkiOpis'] = $hit->KratkiOpis;
$resultSet[] = $resultSetEntry;
}
}
if ($hits_elements)
{
foreach ($hits_elements as $hit) {
$resultSetEntry = array();
$resultSetEntry['ID'] = $hit->ID;
$resultSetEntry['Naziv'] = $hit->Naziv;
$resultSetEntry['UIDJedinica'] = $hit->UIDJedinica;
$resultSetEntry['UIDElement'] = $hit->UID;
$resultSetEntry['Type'] = $hit->Type;
$resultSetEntry['IDElementTip'] = $hit->IDElementTip;
$resultSetEntry['KratkiOpis'] = $hit->KratkiOpis;
$resultSet[] = $resultSetEntry;
}
}
$count_all = ($resultSet) ? count($resultSet) : 0;
$resultSet = array ('result' => $resultSet, 'count_all' => $count_all);
$cache->save($resultSet, $cacheId);
}
$start_id = $criteria->offset;
$end_id = $criteria->offset + $criteria->limit;
fwrite($debug_file, $start_id. ' od ' . $end_id ."\n");
$obj->trazeneJediniceObj = array();
fwrite($debug_file, 'ser'."\n");
fwrite($debug_file, serialize($resultSet['result'])."\n");
fwrite($debug_file, count($resultSet['result'])."\n");
if ( ! empty ($resultSet['result']))
{
for ($result_id = $start_id; $result_id < $end_id; $result_id++)
{
$obj->trazeneJediniceObj[] = array(
'ID' => $resultSet['result'][$result_id]['ID'],
'Naziv' => $resultSet['result'][$result_id]['Naziv'],
'UIDJedinica' => $resultSet['result'][$result_id]['UIDJedinica'],
'UIDElement' => $resultSet['result'][$result_id]['UIDElement'],
'Type' => $resultSet['result'][$result_id]['Type'],
'IDElementTip' => $resultSet['result'][$result_id]['IDElementTip'],
'KratkiOpis' => $resultSet['result'][$result_id]['KratkiOpis'],
);
}
}
$obj->count_all = $resultSet['count_all'];
return $obj;
}
catch (Exception $e)
{
fwrite($debug_file, $e->getMessage() ."\n");
}
但是我得到了这个例外
指定目录中不存在索引。
在文件夹elementi中,用于:
Zend_Search_Lucene::open(ROOT_PATH.'/lucene/elementi')
,我有这些文件:
_cn.cfs
optimization.lock.file
read.lock
read-lock-processing.lock
segments
segments_du
write.lock
这些是我需要的所有文件吗?我没有创建这个索引;我只是用它。如何使用Zend或其他解决方案加载此索引?
答案 0 :(得分:0)
我刚碰到类似的问题,虽然我的文件夹只包含write.lock文件。
这是一个粗略的修复,你可能需要事先考虑其他选项,因为你基本上删除了你的整个索引。无论如何,我设法通过删除文件夹(在你的例子中为ROOT_PATH。&#39; / lucene / elementi&#39;文件夹)来解决它。通过调用以下函数重新创建它。
Zend_Search_Lucene::create(DIRECTORY_HERE);
也许您最好先检查文件夹/文件的权限。