From f5d41cedfd6b4898fcafe5d9ebde9306d4363f49 Mon Sep 17 00:00:00 2001 From: Sean Harvey Date: Tue, 7 Jul 2009 05:38:16 +0000 Subject: [PATCH] BUGFIX Fixed MSSQLDatabase::searchEngine() to search keywords properly by connecting them with AND to go in the CONTAINS() function --- code/MSSQLDatabase.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index dc5f53a..8959c24 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -1091,9 +1091,25 @@ class MSSQLDatabase extends Database { * @param string $keywords Keywords as a string. */ public function searchEngine($classesToSearch, $keywords, $start, $pageLength, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) { - if($this->fullTextEnabled) { - $keywords = Convert::raw2sql(trim($keywords, ' *')); - $htmlEntityKeywords = htmlentities($keywords); + if($this->fullTextEnabled) { + $keywords = Convert::raw2sql(trim($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: $result=DB::query('EXEC sp_help_fulltext_columns');