|
|
@@ -0,0 +1,50 @@
|
|
|
+<?xml version="1.0" encoding="UTF-8"?>
|
|
|
+<!-- Reviewed: no -->
|
|
|
+<!-- EN-Revision: 19777 -->
|
|
|
+<sect1 id="learning.lucene.pagination">
|
|
|
+ <title>検索結果のページ化</title>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ <link linkend="learning.lucene.searching.identifiers">上記</link>
|
|
|
+ のように、検索結果ヒット・オブジェクトでは、格納された文書項目に対して
|
|
|
+ レイジー・ローディングを使います。格納された項目のどれかがアクセスされると、
|
|
|
+ 全ての文書が読み込まれます。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <para>
|
|
|
+ もし、実際にはその一部だけで作業したい場合、全ての文書を取り出ししないでください。
|
|
|
+ 検索結果を調べて、次のスクリプト実行中に文書をインデックスから取り出すために、
|
|
|
+ 文書ID(任意にスコア)をどこかに保存してください。
|
|
|
+ </para>
|
|
|
+
|
|
|
+ <example id="learning.lucene.pagination.example">
|
|
|
+ <title>検索結果のページ化例</title>
|
|
|
+
|
|
|
+ <programlisting language="php"><![CDATA[
|
|
|
+$cacheId = md5($query);
|
|
|
+
|
|
|
+if (!$resultSet = $cache->load($cacheId)) {
|
|
|
+ $hits = $index->find($query);
|
|
|
+ $resultSet = array();
|
|
|
+ foreach ($hits as $hit) {
|
|
|
+ $resultSetEntry = array();
|
|
|
+ $resultSetEntry['id'] = $hit->id;
|
|
|
+ $resultSetEntry['score'] = $hit->score;
|
|
|
+
|
|
|
+ $resultSet[] = $resultSetEntry;
|
|
|
+ }
|
|
|
+
|
|
|
+ $cache->save($resultSet, $cacheId);
|
|
|
+}
|
|
|
+
|
|
|
+$publishedResultSet = array();
|
|
|
+for ($resultId = $startId; $resultId < $endId; $resultId++) {
|
|
|
+ $publishedResultSet[$resultId] = array(
|
|
|
+ 'id' => $resultSet[$resultId]['id'],
|
|
|
+ 'score' => $resultSet[$resultId]['score'],
|
|
|
+ 'doc' => $index->getDocument($resultSet[$resultId]['id']),
|
|
|
+ );
|
|
|
+}
|
|
|
+]]></programlisting>
|
|
|
+ </example>
|
|
|
+</sect1>
|