2

我想使用 Zend_Paginator::setCache() 从 Zend_Lucene_Search 缓存我的结果

我收到以下错误:

Warning: fseek() expects parameter 1 to be resource, integer given

这是代码的一部分:

// Load index
$index = Zend_Search_Lucene::open(APPLICATION_PATH . '/indexes');
// Paginate
$paginator = Zend_Paginator::factory($index->find($query));
$paginator->setCache($this->_cache);
$paginator->setItemCountPerPage($items);
$paginator->setCurrentPageNumber($page);
// Send to view
$this->view->hits = $paginator;

在站点的其他区域中,我使用相同的技术来缓存不是来自 Zend_Lucene_Search 的分页结果,这很好用。

我在某处读到,将结果存储在会话或缓存中会破坏 lucene 文档,并且您必须将 QueryHit 对象转换为 stdClass 对象,但是如何?这行得通吗?

4

1 回答 1

3

好的解决了,我想多了

$hits = $index->find($query);
$this->view->totalHits = count($hits);
// Convert to stdClass to allow caching
foreach ($hits as $i => $hit) {
    $resultsArray[$i] = new stdClass();
    $doc = $hit->getDocument();
    foreach($doc->getFieldNames() as $field){
        $resultsArray[$i]->{$field} = $hit->{$field};
    }
}
// Paginate
$paginator = Zend_Paginator::factory($resultsArray);
$paginator->setCache($this->_cache);
$paginator->setItemCountPerPage($items);
$paginator->setCurrentPageNumber($page);
// Send to view
$this->view->hits = $paginator;
于 2010-11-03T15:08:10.590 回答