我想使用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对象,但是如何?这有用吗?
答案 0 :(得分: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;