BUGFIX Fixed MSSQLDatabase::searchEngine() to search keywords properly by connecting them with AND to go in the CONTAINS() function

This commit is contained in:
Sean Harvey 2009-07-07 05:38:16 +00:00
parent 31cedd108b
commit f5d41cedfd

View File

@ -1092,9 +1092,25 @@ class MSSQLDatabase extends 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) {
if($this->fullTextEnabled) { if($this->fullTextEnabled) {
$keywords = Convert::raw2sql(trim($keywords, ' *')); $keywords = Convert::raw2sql(trim($keywords));
$htmlEntityKeywords = htmlentities($keywords); $htmlEntityKeywords = htmlentities($keywords);
$keywordList = explode(' ', $keywords);
if($keywordList) {
foreach($keywordList as $index => $keyword) {
$keywordList[$index] = "\"{$keyword}\"";
}
$keywords = implode(' AND ', $keywordList);
}
$htmlEntityKeywordList = explode(' ', $htmlEntityKeywords);
if($htmlEntityKeywordList) {
foreach($htmlEntityKeywordList as $index => $keyword) {
$htmlEntityKeywordList[$index] = "\"{$keyword}\"";
}
$htmlEntityKeywords = implode(' AND ', $htmlEntityKeywordList);
}
//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');
if (!$result->numRecords()) throw Exception('there are no full text columns to search'); if (!$result->numRecords()) throw Exception('there are no full text columns to search');