Zend搜索Lucene索引没有';不存在于指定的目录中


Zend search Lucene index doesn't exist in the specified directory

我正在构建一个索引搜索。我这样打开索引:

$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");
}

但我得到了这个例外

指定的目录中不存在索引。

在文件夹elemini中,它用于: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或其他解决方案加载此索引?

我刚刚遇到了一个类似的问题,尽管我的文件夹只包含write.lock文件。

这是一个有点粗糙的修复方法,你可能需要事先考虑其他选项,因为你基本上是在删除整个索引。无论如何,我设法通过删除文件夹(在您的示例中是ROOT_PATH./lucene/elementi'文件夹)&通过调用以下函数重新创建它。

Zend_Search_Lucene::create(DIRECTORY_HERE);

也许你最好先检查文件夹/文件的权限。