【问题标题】:Zend search Lucene index doesn't exist in the specified directoryZend 搜索 Lucene 索引在指定目录中不存在
【发布时间】:2015-04-26 10:09:36
【问题描述】:

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

$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 或其他解决方案加载此索引?

【问题讨论】:

    标签: php zend-framework lucene


    【解决方案1】:

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

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

    Zend_Search_Lucene::create(DIRECTORY_HERE);
    

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

    【讨论】:

      猜你喜欢
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-09
      • 1970-01-01
      相关资源
      最近更新 更多