mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
BUGFIX: fixed pagination of search results not loading on pages other than the first
This commit is contained in:
parent
842043a8e3
commit
8ba0bcea69
@ -11,8 +11,6 @@
|
||||
class DocumentationSearch {
|
||||
|
||||
private static $enabled = false;
|
||||
|
||||
private $query;
|
||||
|
||||
private $results;
|
||||
|
||||
@ -104,9 +102,7 @@ class DocumentationSearch {
|
||||
*
|
||||
* Rebuilds the index if it out of date
|
||||
*/
|
||||
public function performSearch($query) {
|
||||
$this->query = $query;
|
||||
|
||||
public function performSearch($query) {
|
||||
$index = Zend_Search_Lucene::open(self::get_index_location());
|
||||
|
||||
Zend_Search_Lucene::setResultSetLimit(200);
|
||||
@ -118,7 +114,7 @@ class DocumentationSearch {
|
||||
/**
|
||||
* @return DataObjectSet
|
||||
*/
|
||||
public function getDataArrayFromHits($start) {
|
||||
public function getDataArrayFromHits($request) {
|
||||
$data = array(
|
||||
'Results' => null,
|
||||
'Query' => null,
|
||||
@ -132,7 +128,10 @@ class DocumentationSearch {
|
||||
'NextUrl' => DBField::create('Text', 'false'),
|
||||
'SearchPages' => new DataObjectSet()
|
||||
);
|
||||
|
||||
|
||||
$start = ($request->requestVar('start')) ? (int)$request->requestVar('start') : 0;
|
||||
$query = ($request->requestVar('Search')) ? $request->requestVar('Search') : '';
|
||||
|
||||
$pageLength = 10;
|
||||
$currentPage = floor( $start / $pageLength ) + 1;
|
||||
|
||||
@ -165,7 +164,7 @@ class DocumentationSearch {
|
||||
}
|
||||
|
||||
$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['TotalPages'] = DBField::create('Text', $totalPages);
|
||||
$data['ThisPage'] = DBField::create('Text', $currentPage);
|
||||
|
@ -95,7 +95,7 @@ class DocumentationViewer extends Controller {
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request) {
|
||||
// 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();
|
||||
$secondParam = $request->shift();
|
||||
@ -608,7 +608,7 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
$form = new Form($this, 'DocumentationSearchForm', $fields, $actions);
|
||||
$form->disableSecurityToken();
|
||||
|
||||
$form->setFormMethod('get');
|
||||
$form->setFormAction('home/DocumentationSearchForm');
|
||||
|
||||
return $form;
|
||||
@ -617,14 +617,11 @@ class DocumentationViewer extends Controller {
|
||||
/**
|
||||
* Past straight to results, display and encode the query
|
||||
*/
|
||||
function results($data, $form) {
|
||||
$query = (isset($data['Search'])) ? urlencode($data['Search']) : "";
|
||||
$start = (isset($_GET['start'])) ? (int) $_GET['start'] : 0;
|
||||
|
||||
function results($data, $form, $request) {
|
||||
$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'));
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<p>Showing page $ThisPage of $TotalPages</p>
|
||||
<% control Results %>
|
||||
<h2><a href="$Link">$Title</a></h2>
|
||||
$Content.LimitWordCountXML
|
||||
<p>$Content.LimitCharacters(200)</p>
|
||||
<% end_control %>
|
||||
|
||||
<% if SearchPages %>
|
||||
|
Loading…
Reference in New Issue
Block a user