mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-09-30 21:29:00 +02:00
Merge pull request #33 from PapaBearNZ/search-engine-patch-1.1
FIX Total Items count on Search
This commit is contained in:
commit
606879243a
@ -1886,12 +1886,14 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
|
|
||||||
$fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
|
$fullQuery = "SELECT * FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
|
||||||
|
|
||||||
|
// Get the total items in this search
|
||||||
|
$totalItemsQuery = "SELECT COUNT(*) AS totalitems FROM (" . implode(" UNION ", $tables) . ") AS q1";
|
||||||
|
$totalCount = DB::query($totalItemsQuery);
|
||||||
|
|
||||||
// Get records
|
// Get records
|
||||||
$records = DB::query($fullQuery);
|
$records = DB::query($fullQuery);
|
||||||
$totalCount=0;
|
|
||||||
foreach($records as $record){
|
foreach($records as $record){
|
||||||
$objects[] = new $record['ClassName']($record);
|
$objects[] = new $record['ClassName']($record);
|
||||||
$totalCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(isset($objects)) $results = new ArrayList($objects);
|
if(isset($objects)) $results = new ArrayList($objects);
|
||||||
@ -1900,7 +1902,7 @@ class PostgreSQLDatabase extends SS_Database {
|
|||||||
$list->setLimitItems(false);
|
$list->setLimitItems(false);
|
||||||
$list->setPageStart($start);
|
$list->setPageStart($start);
|
||||||
$list->setPageLength($pageLength);
|
$list->setPageLength($pageLength);
|
||||||
$list->setTotalItems($totalCount);
|
$list->setTotalItems($totalCount->value());
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user