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));
@ -1175,8 +1175,8 @@ class MSSQLDatabase extends SS_Database {
} }
//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:
$result=DB::query('EXEC sp_help_fulltext_columns'); $result = DB::query('EXEC sp_help_fulltext_columns');
$tables= array(); $tables = array();
foreach($result as $row){ foreach($result as $row){
if(substr($row['TABLE_NAME'], -5)!='_Live' && substr($row['TABLE_NAME'], -9)!='_versions') { if(substr($row['TABLE_NAME'], -5)!='_Live' && substr($row['TABLE_NAME'], -9)!='_versions') {
@ -1190,30 +1190,25 @@ class MSSQLDatabase extends SS_Database {
$tables[] = $thisSql; $tables[] = $thisSql;
} }
} }
$query = implode(' UNION ', $tables);
$result = DB::query($query);
$totalCount = 0; $totalCount = 0;
foreach($tables as $q) { foreach($result as $row) {
$qR = DB::query($q); $record = DataObject::get_by_id($row['Source'], $row['ID']);
$totalCount += $qR->numRecords(); if($record->canView()) {
$results->push($record);
$totalCount++;
}
} }
//We'll do a union query on all of these tables... it's easier! $results->setPageLimits($start, $pageLength, $totalCount);
$query=implode(' UNION ', $tables);
return $results;
$result=DB::query($query);
foreach($result as $row){
$row_result=DataObject::get_by_id($row['Source'], $row['ID']);
if($row_result->canView()) $searchResults->push($row_result);
}
$searchResults->setPageLimits($start, $pageLength, $totalCount);
return $searchResults;
} }
/** /**
* Allow auto-increment primary key editing on the given table. * Allow auto-increment primary key editing on the given table.
* Some databases need to enable this specially. * Some databases need to enable this specially.