mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 09:05:56 +00:00
BUGFIX: fixed pagination of search results not loading on pages other than the first
This commit is contained in:
parent
842043a8e3
commit
8ba0bcea69
@ -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);
|
||||||
|
@ -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'));
|
||||||
}
|
}
|
||||||
|
@ -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 %>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user