Merge pull request #80 from kinglozzer/fix-searchengine

Fix PostgreSQLDatabase::searchEngine()
This commit is contained in:
Daniel Hensby 2017-11-25 18:09:58 +00:00 committed by GitHub
commit d110b92fc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -352,16 +352,13 @@ class PostgreSQLDatabase extends SS_Database {
if($keywords) $orderBy = " ORDER BY $sortBy";
else $orderBy='';
$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);
$fullQuery = "SELECT *, count(*) OVER() as _fullcount FROM (" . implode(" UNION ", $tables) . ") AS q1 $orderBy LIMIT $limit OFFSET $offset";
// Get records
$records = $this->preparedQuery($fullQuery, $tableParameters);
foreach($records as $record){
$objects[] = new $record['ClassName']($record);
$objects[] = Injector::inst()->createWithArgs($record['ClassName'], array($record));
$totalCount = $record['_fullcount'];
}
if(isset($objects)) $results = new ArrayList($objects);
@ -370,7 +367,7 @@ class PostgreSQLDatabase extends SS_Database {
$list->setLimitItems(false);
$list->setPageStart($start);
$list->setPageLength($pageLength);
$list->setTotalItems($totalCount->value());
$list->setTotalItems($totalCount);
return $list;
}