BUGFIX: fixed pagination of search results not loading on pages other than the first

This commit is contained in:
Will Rossiter 2010-12-22 08:44:46 +00:00
parent 842043a8e3
commit 8ba0bcea69
3 changed files with 13 additions and 17 deletions

View File

@ -12,8 +12,6 @@ class DocumentationSearch {
private static $enabled = false; private static $enabled = false;
private $query;
private $results; private $results;
private $totalResults; private $totalResults;
@ -105,8 +103,6 @@ class DocumentationSearch {
* Rebuilds the index if it out of date * Rebuilds the index if it out of date
*/ */
public function performSearch($query) { public function performSearch($query) {
$this->query = $query;
$index = Zend_Search_Lucene::open(self::get_index_location()); $index = Zend_Search_Lucene::open(self::get_index_location());
Zend_Search_Lucene::setResultSetLimit(200); Zend_Search_Lucene::setResultSetLimit(200);
@ -118,7 +114,7 @@ class DocumentationSearch {
/** /**
* @return DataObjectSet * @return DataObjectSet
*/ */
public function getDataArrayFromHits($start) { public function getDataArrayFromHits($request) {
$data = array( $data = array(
'Results' => null, 'Results' => null,
'Query' => null, 'Query' => null,
@ -133,6 +129,9 @@ class DocumentationSearch {
'SearchPages' => new DataObjectSet() 'SearchPages' => new DataObjectSet()
); );
$start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0;
$query = ($request->requestVar('Search')) ? $request->requestVar('Search') : '';
$pageLength = 10; $pageLength = 10;
$currentPage = floor( $start / $pageLength ) + 1; $currentPage = floor( $start / $pageLength ) + 1;
@ -165,7 +164,7 @@ class DocumentationSearch {
} }
$data['Results'] = $results; $data['Results'] = $results;
$data['Query'] = DBField::create('Text', $this->query); $data['Query'] = DBField::create('Text', $query);
$data['TotalResults'] = DBField::create('Text', count($this->results)); $data['TotalResults'] = DBField::create('Text', count($this->results));
$data['TotalPages'] = DBField::create('Text', $totalPages); $data['TotalPages'] = DBField::create('Text', $totalPages);
$data['ThisPage'] = DBField::create('Text', $currentPage); $data['ThisPage'] = DBField::create('Text', $currentPage);

View File

@ -95,7 +95,7 @@ class DocumentationViewer extends Controller {
*/ */
public function handleRequest(SS_HTTPRequest $request) { public function handleRequest(SS_HTTPRequest $request) {
// if we submitted a form, let that pass // if we submitted a form, let that pass
if(!$request->isGET()) return parent::handleRequest($request); if(!$request->isGET() || isset($_GET['action_results'])) return parent::handleRequest($request);
$firstParam = ($request->param('Action')) ? $request->param('Action') : $request->shift(); $firstParam = ($request->param('Action')) ? $request->param('Action') : $request->shift();
$secondParam = $request->shift(); $secondParam = $request->shift();
@ -608,7 +608,7 @@ class DocumentationViewer extends Controller {
$form = new Form($this, 'DocumentationSearchForm', $fields, $actions); $form = new Form($this, 'DocumentationSearchForm', $fields, $actions);
$form->disableSecurityToken(); $form->disableSecurityToken();
$form->setFormMethod('get');
$form->setFormAction('home/DocumentationSearchForm'); $form->setFormAction('home/DocumentationSearchForm');
return $form; return $form;
@ -617,14 +617,11 @@ class DocumentationViewer extends Controller {
/** /**
* Past straight to results, display and encode the query * Past straight to results, display and encode the query
*/ */
function results($data, $form) { function results($data, $form, $request) {
$query = (isset($data['Search'])) ? urlencode($data['Search']) : "";
$start = (isset($_GET['start'])) ? (int) $_GET['start'] : 0;
$search = new DocumentationSearch(); $search = new DocumentationSearch();
$search->performSearch($query); $search->performSearch($form->dataFieldByName('Search')->dataValue());
$data = $search->getDataArrayFromHits($start); $data = $search->getDataArrayFromHits($request);
return $this->customise($data)->renderWith(array('DocumentationViewer_results', 'DocumentationViewer')); return $this->customise($data)->renderWith(array('DocumentationViewer_results', 'DocumentationViewer'));
} }

View File

@ -6,7 +6,7 @@
<p>Showing page $ThisPage of $TotalPages</p> <p>Showing page $ThisPage of $TotalPages</p>
<% control Results %> <% control Results %>
<h2><a href="$Link">$Title</a></h2> <h2><a href="$Link">$Title</a></h2>
$Content.LimitWordCountXML <p>$Content.LimitCharacters(200)</p>
<% end_control %> <% end_control %>
<% if SearchPages %> <% if SearchPages %>