Supported queries | Getting Started with Zend_Search_Lucene Programmer's Reference Guide | Getting Started with Zend_Paginator

# Search result pagination

As mentioned above, search result hit objects use lazy loading for stored document fields. When any stored field is accessed, the complete document is loaded.

Do not retrieve all documents if you actually need to work only with some portion of them. Go through the search results and store document IDs (and optionally the score) somewhere to retrive documents from the index during the next script execution.

Example #1 Search result pagination example

1. $cacheId = md5 ($query);
3. if (!$resultSet = $cache->load($cacheId)) {
4. $hits = $index->find($query);
5. $resultSet = array ();
6. foreach ($hits as $hit) {
7. $resultSetEntry = array ();
8. $resultSetEntry['id'] = $hit->id;
9. $resultSetEntry['score'] = $hit->score;
11. $resultSet[] = $resultSetEntry;
12. }
14. $cache->save($resultSet, $cacheId);
15. }
17. $publishedResultSet = array ();
18. for ($resultId = $startId; $resultId < $endId; $resultId++) {
19. $publishedResultSet[$resultId] = array (
20. 'id' => $resultSet[$resultId]['id'],
21. 'score' => $resultSet[$resultId]['score'],
22. 'doc' => $index->getDocument($resultSet[$resultId]['id']),
23. );
24. }

Supported queries | Getting Started with Zend_Search_Lucene Programmer's Reference Guide | Getting Started with Zend_Paginator