ENCHANCEMENT: Added fullTextEnabled property to MSSQLDatabase object, to let developers completely disabled all fulltext functionality.

This commit is contained in:
Sam Minnee 2009-05-08 03:37:31 +00:00
parent 3fbf62c4cd
commit 87760aa5b3

View File

@ -29,6 +29,11 @@ class MSSQLDatabase extends Database {
*/
private $database;
/**
* Does this database have full-text index supprt
*/
protected $fullTextEnabled = false;
/**
* Connect to a MS SQL database.
* @param array $parameters An map of parameters, which should include:
@ -65,10 +70,12 @@ class MSSQLDatabase extends Database {
* TODO: VERY IMPORTANT: move this so it only gets called upon a dev/build action
*/
function createFullTextCatalog(){
if($this->fullTextEnabled) {
$this->query("exec sp_fulltext_database 'enable';");
$result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value();
if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
}
}
/**
* Not implemented, needed for PDO
*/
@ -246,7 +253,6 @@ class MSSQLDatabase extends Database {
if($indexes) foreach($indexes as $k => $v) $indexSchemas .= $this->getIndexSqlDefinition($tableName, $k, $v) . "\n";
$this->query($indexSchemas);
}
/**
@ -305,9 +311,9 @@ class MSSQLDatabase extends Database {
}
}
foreach($alterIndexList as $alteration)
if($alteration!='')
$this->query($alteration);
foreach($alterIndexList as $alteration) {
if($alteration!='') $this->query($alteration);
}
}
/*
@ -520,6 +526,7 @@ class MSSQLDatabase extends Database {
} else {
//create a type-specific index
if($indexSpec['type']=='fulltext'){
if($this->fullTextEnabled) {
//Enable full text search.
$this->createFullTextCatalog();
@ -534,6 +541,7 @@ class MSSQLDatabase extends Database {
return $drop . "CREATE FULLTEXT INDEX ON \"$tableName\" ({$indexSpec['value']}) " .
"KEY INDEX $primary_key WITH CHANGE_TRACKING AUTO;";
}
}
@ -592,6 +600,7 @@ class MSSQLDatabase extends Database {
}
//Now we need to check to see if we have any fulltext indexes attached to this table:
if($this->fullTextEnabled) {
$result=DB::query('EXEC sp_help_fulltext_columns;');
$columns='';
foreach($result as $row){
@ -606,6 +615,7 @@ class MSSQLDatabase extends Database {
$indexList['SearchFields']['indexname']='SearchFields';
$indexList['SearchFields']['spec']='fulltext (' . $columns . ')';
}
}
return isset($indexList) ? $indexList : null;
@ -1002,7 +1012,7 @@ class MSSQLDatabase extends Database {
* @param string $keywords Keywords as a string.
*/
public function searchEngine($classesToSearch, $keywords, $pageLength = null, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
if($this->fullTextEnabled) {
$result=DB::query('EXEC sp_help_fulltext_columns;');
//Get a list of all the tables and columns we'll be searching on:
@ -1024,6 +1034,7 @@ class MSSQLDatabase extends Database {
}
$searchResults->setPageLimits($start, $pageLength, $totalCount);
}
return $searchResults;
}