Skip to content

Instantly share code, notes, and snippets.

@yentsun
Created February 1, 2012 14:09
Show Gist options
  • Save yentsun/1717137 to your computer and use it in GitHub Desktop.
Save yentsun/1717137 to your computer and use it in GitHub Desktop.
An example of paginating Zend_Lucene search results
<?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);
@yentsun
Copy link
Author

yentsun commented Feb 1, 2012

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment