BUGFIX MSSQLDatabase::searchEngine() no longer relies on MSSQLQuery::numRecords() which doesn't always work properly anyway, instead it counts if the record can be viewed and was pushed into the result DataObjectSet

This commit is contained in:
Sean Harvey 2010-05-19 12:11:33 +00:00
parent 07c4800374
commit 888dc64c0a

View File

@ -1150,9 +1150,9 @@ class MSSQLDatabase extends SS_Database {
* @return object DataObjectSet of result pages * @return object DataObjectSet of result pages
*/ */
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) {
$searchResults = new DataObjectSet(); $results = new DataObjectSet();
if(!$this->fullTextEnabled()) { if(!$this->fullTextEnabled()) {
return $searchResults; return $results;
} }
$keywords = Convert::raw2sql(trim($keywords)); $keywords = Convert::raw2sql(trim($keywords));
@ -1190,28 +1190,23 @@ class MSSQLDatabase extends SS_Database {
$tables[] = $thisSql; $tables[] = $thisSql;
} }
} }
$totalCount = 0;
foreach($tables as $q) {
$qR = DB::query($q);
$totalCount += $qR->numRecords();
}
//We'll do a union query on all of these tables... it's easier!
$query = implode(' UNION ', $tables); $query = implode(' UNION ', $tables);
$result = DB::query($query); $result = DB::query($query);
$totalCount = 0;
foreach($result as $row) { foreach($result as $row) {
$row_result=DataObject::get_by_id($row['Source'], $row['ID']); $record = DataObject::get_by_id($row['Source'], $row['ID']);
if($row_result->canView()) $searchResults->push($row_result); if($record->canView()) {
$results->push($record);
$totalCount++;
}
} }
$searchResults->setPageLimits($start, $pageLength, $totalCount); $results->setPageLimits($start, $pageLength, $totalCount);
return $searchResults; return $results;
} }
/** /**