Перевод "Getting Started with Zend_Search_Lucene. Search result pagination"

Zend, “Getting Started with Zend_Search_Lucene. Search result pagination”, public translation into Russian from English More about this translation.

See also 44 similar translations

Translate into another language.

Participants

Join Translated.by to translate! If you already have a Translated.by account, please sign in.
If you do not want to register an account, you can sign in with OpenID.
Pages: ← previous Ctrl next → next untranslated
1

Getting Started with Zend_Search_Lucene. 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

  01. $cacheId = md5($query);

  02.  

  03. if (!$resultSet = $cache->load($cacheId)) {

  04.     $hits = $index->find($query);

  05.     $resultSet = array();

  06.     foreach ($hits as $hit) {

  07.         $resultSetEntry          = array();

  08.         $resultSetEntry['id']    = $hit->id;

  09.         $resultSetEntry['score'] = $hit->score;

  10.  

  11.         $resultSet[] = $resultSetEntry;

  12.     }

  13.  

  14.     $cache->save($resultSet, $cacheId);

  15. }

  16.  

  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. }

Pages: ← previous Ctrl next → next untranslated
1