public function paginate($page, $limit = 10) { $pager = new sfLucenePager($this->_model, $this->_queryString, $limit); $pager->setPage($page); $pager->init(); return $pager; }
public function executeSearch() { $feed = new sfAtom1Feed(); $feed->setTitle('Hoydaa Snippets'); $feed->setLink('http://codesnippet.hoydaa.org'); $feed->setAuthorEmail('*****@*****.**'); $feed->setAuthorName('Hoydaa Snippets'); $querystring = $this->getRequestParameter('q'); $query = new sfLuceneCriteria($this->getLuceneInstance()); $query->addDescendingSortBy('createdat'); $query->addSane($querystring); $pager = new sfLucenePager($this->getLuceneInstance()->friendlyFind($query)); $num = $pager->getNbResults(); if ($num > 0) { $pager->setMaxPerPage(10); $pager->setPage(1); foreach ($pager->getResults() as $result) { $item = new sfFeedItem(); $item->setTitle($result->getTitle()); $item->setLink('snippet/show?id=' . $result->getId()); $item->setAuthorName($result->getContributor()); $item->setPubDate(strtotime($result->getCreatedAt())); //$item->setAuthorEmail(($code->getSfGuardUser() ? // $code->getSfGuardUser()->getProfile()->getEmail() : $code->getEmail())); $item->setUniqueId($result->getId()); $item->setDescription($result->getSummary()); $feed->addItem($item); } } $this->feed = $feed; $this->setTemplate('feed'); }
} try { new sfLucenePager(array(), null); $t->fail('__construct() must have a search instance'); } catch (Exception $e) { $t->pass('__construct() must have a search instance'); } try { $results = new sfLucenePager(range(0, 1000), $lucene); $t->pass('__construct() accepts an array'); } catch (Exception $e) { $t->fail('__construct() accepts an array'); } $t->diag('testing basic pagination functions'); try { $results->setPage(2); $t->pass('->setPage() accepts a integer page'); } catch (Exception $e) { $t->fail('->setPage() accepts a integer page'); } try { $results->setMaxPerPage(10); $t->pass('->setMaxPerPage() accepts an integer per page'); } catch (Exception $e) { $t->fail('->setMaxPerPage() accepts an integer per page'); } $t->is($results->getPage(), 2, '->getPage() returns current page'); $t->is($results->getMaxPerPage(), 10, '->getMaxPerPage() returns the max per page'); $t->is($results->getNbResults(), 1001, '->getNbResults() returns the total number of results'); $t->ok($results->haveToPaginate(), '->haveToPaginate() returns correct value'); $results->setPage(0);
try { new sfLucenePager('a', $lucene); $t->fail('__construct() rejects a non-array'); } catch (Exception $e) { $t->pass('__construct() rejects a non-array'); } $response = $lucene->find('dummy search'); try { $pager = new sfLucenePager(new sfLuceneResults($response, $lucene)); $t->pass('__construct() accepts sfLuceneResults'); } catch (Exception $e) { $t->fail('__construct() accepts sfLuceneResults'); } $t->diag('testing basic pagination functions'); try { $pager->setPage(2); $t->pass('->setPage() accepts a integer page'); } catch (Exception $e) { $t->fail('->setPage() accepts a integer page'); } try { $pager->setMaxPerPage(10); $t->pass('->setMaxPerPage() accepts an integer per page'); } catch (Exception $e) { $t->fail('->setMaxPerPage() accepts an integer per page'); } $t->is($pager->getPage(), 2, '->getPage() returns current page'); $t->is($pager->getMaxPerPage(), 10, '->getMaxPerPage() returns the max per page'); $t->is($pager->getNbResults(), 1001, '->getNbResults() returns the total number of results'); $t->ok($pager->haveToPaginate(), '->haveToPaginate() returns correct value'); $pager->setPage(0);