mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 06:05:53 +00:00
BUGFIX: limit the query results for pagination
This commit is contained in:
parent
2aff1a9196
commit
2b5f25455f
@ -1228,9 +1228,8 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
|
public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
|
||||||
$results = new DataObjectSet();
|
$results = new DataObjectSet();
|
||||||
if(!$this->fullTextEnabled()) {
|
if(!$this->fullTextEnabled()) return $results;
|
||||||
return $results;
|
if (substr($sortBy, 0, 9)!='Relevance') user_error("Non-relevance sort not supported.", E_USER_ERROR);
|
||||||
}
|
|
||||||
|
|
||||||
//Get a list of all the tables and columns we'll be searching on:
|
//Get a list of all the tables and columns we'll be searching on:
|
||||||
$fulltextColumns = DB::query('EXEC sp_help_fulltext_columns');
|
$fulltextColumns = DB::query('EXEC sp_help_fulltext_columns');
|
||||||
@ -1266,7 +1265,7 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
$queries[$tableName]->orderby = null;
|
$queries[$tableName]->orderby = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate SQL and count totals
|
// Generate SQL
|
||||||
$querySQLs = array();
|
$querySQLs = array();
|
||||||
foreach($queries as $query) {
|
foreach($queries as $query) {
|
||||||
$querySQLs[] = $query->sql();
|
$querySQLs[] = $query->sql();
|
||||||
@ -1278,14 +1277,18 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
// Perform the search
|
// Perform the search
|
||||||
$result = DB::query($fullQuery);
|
$result = DB::query($fullQuery);
|
||||||
|
|
||||||
// Regenerate the DataObjects, apply security
|
// Regenerate DataObjectSet
|
||||||
$totalCount = 0;
|
$totalCount = $result->numRecords();
|
||||||
|
$current = -1;
|
||||||
|
$results = new DataObjectSet();
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$record = DataObject::get_by_id($row['Source'], $row['ID']);
|
$current++;
|
||||||
if($record->canView()) {
|
|
||||||
$results->push($record);
|
// Select a subset for paging
|
||||||
$totalCount++;
|
if ($current>=$start+$pageLength) break;
|
||||||
}
|
if ($current<$start) continue;
|
||||||
|
|
||||||
|
$results->push(DataObject::get_by_id($row['Source'], $row['ID']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$results->setPageLimits($start, $pageLength, $totalCount);
|
$results->setPageLimits($start, $pageLength, $totalCount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user