开发者

Use zend_lucene_search with Zend_Paginator cache

I want to cache my results from Zend_Lucene_Search using Zend_Paginator::setCache()

I get the following error:

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

Here is the portion of code:

// 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开发者_StackOverflow->hits = $paginator;

In other areas of the site where I use the same technique to cache paginated results that are not from Zend_Lucene_Search, this works fine.

I read somewhere that storing results in a session or cache destroys the lucene document and that you have to convert the QueryHit objects to stdClass objects, but how? Does this work?


Ok solved it, I was overthinking it

$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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜