Created
February 1, 2012 14:09
-
-
Save yentsun/1717137 to your computer and use it in GitHub Desktop.
An example of paginating Zend_Lucene search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$index = Zend_Search_Lucene::open(your_index_dir); | |
$query = 'some search query'; | |
$result = $index->find($query); | |
$perPage = 20; | |
$page = 5; | |
$range = 4; | |
Zend_Paginator::setDefaultScrollingStyle('Elastic'); | |
Zend_View_Helper_PaginationControl::setDefaultViewPartial('_pagination.phtml'); //your pagination partial | |
$paginator = Zend_Paginator::factory($result); | |
$paginator->setCurrentPageNumber($page); | |
$paginator->setItemCountPerPage($perPage); | |
$paginator->setPageRange($range); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As Zend_Paginator::factory accepts Iterator object and Zend_Search_Lucene_Proxy::find returns an Iterator object you could implement 'native' pagination.
Of course, there is a drawback - you are dealing with the whole resultset everytime (unlike offsetted & limited if you pass a Zend_DB_Select object to the paginator factory) but I guess general queries to Zend_Lucene are cheap.