mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
ENCHANCEMENT: Added fullTextEnabled property to MSSQLDatabase object, to let developers completely disabled all fulltext functionality.
This commit is contained in:
parent
3fbf62c4cd
commit
87760aa5b3
@ -29,6 +29,11 @@ class MSSQLDatabase extends Database {
|
|||||||
*/
|
*/
|
||||||
private $database;
|
private $database;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this database have full-text index supprt
|
||||||
|
*/
|
||||||
|
protected $fullTextEnabled = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a MS SQL database.
|
* Connect to a MS SQL database.
|
||||||
* @param array $parameters An map of parameters, which should include:
|
* @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
|
* TODO: VERY IMPORTANT: move this so it only gets called upon a dev/build action
|
||||||
*/
|
*/
|
||||||
function createFullTextCatalog(){
|
function createFullTextCatalog(){
|
||||||
|
if($this->fullTextEnabled) {
|
||||||
$this->query("exec sp_fulltext_database 'enable';");
|
$this->query("exec sp_fulltext_database 'enable';");
|
||||||
$result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value();
|
$result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value();
|
||||||
if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
|
if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Not implemented, needed for PDO
|
* 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";
|
if($indexes) foreach($indexes as $k => $v) $indexSchemas .= $this->getIndexSqlDefinition($tableName, $k, $v) . "\n";
|
||||||
|
|
||||||
$this->query($indexSchemas);
|
$this->query($indexSchemas);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -305,9 +311,9 @@ class MSSQLDatabase extends Database {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($alterIndexList as $alteration)
|
foreach($alterIndexList as $alteration) {
|
||||||
if($alteration!='')
|
if($alteration!='') $this->query($alteration);
|
||||||
$this->query($alteration);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -520,6 +526,7 @@ class MSSQLDatabase extends Database {
|
|||||||
} else {
|
} else {
|
||||||
//create a type-specific index
|
//create a type-specific index
|
||||||
if($indexSpec['type']=='fulltext'){
|
if($indexSpec['type']=='fulltext'){
|
||||||
|
if($this->fullTextEnabled) {
|
||||||
//Enable full text search.
|
//Enable full text search.
|
||||||
$this->createFullTextCatalog();
|
$this->createFullTextCatalog();
|
||||||
|
|
||||||
@ -534,6 +541,7 @@ class MSSQLDatabase extends Database {
|
|||||||
|
|
||||||
return $drop . "CREATE FULLTEXT INDEX ON \"$tableName\" ({$indexSpec['value']}) " .
|
return $drop . "CREATE FULLTEXT INDEX ON \"$tableName\" ({$indexSpec['value']}) " .
|
||||||
"KEY INDEX $primary_key WITH CHANGE_TRACKING AUTO;";
|
"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:
|
//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;');
|
$result=DB::query('EXEC sp_help_fulltext_columns;');
|
||||||
$columns='';
|
$columns='';
|
||||||
foreach($result as $row){
|
foreach($result as $row){
|
||||||
@ -606,6 +615,7 @@ class MSSQLDatabase extends Database {
|
|||||||
$indexList['SearchFields']['indexname']='SearchFields';
|
$indexList['SearchFields']['indexname']='SearchFields';
|
||||||
$indexList['SearchFields']['spec']='fulltext (' . $columns . ')';
|
$indexList['SearchFields']['spec']='fulltext (' . $columns . ')';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return isset($indexList) ? $indexList : null;
|
return isset($indexList) ? $indexList : null;
|
||||||
|
|
||||||
@ -1002,7 +1012,7 @@ class MSSQLDatabase extends Database {
|
|||||||
* @param string $keywords Keywords as a string.
|
* @param string $keywords Keywords as a string.
|
||||||
*/
|
*/
|
||||||
public function searchEngine($classesToSearch, $keywords, $pageLength = null, $sortBy = "Relevance DESC", $extraFilter = "", $booleanSearch = false, $alternativeFileFilter = "", $invertedMatch = false) {
|
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;');
|
$result=DB::query('EXEC sp_help_fulltext_columns;');
|
||||||
|
|
||||||
//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:
|
||||||
@ -1024,6 +1034,7 @@ class MSSQLDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$searchResults->setPageLimits($start, $pageLength, $totalCount);
|
$searchResults->setPageLimits($start, $pageLength, $totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
return $searchResults;
|
return $searchResults;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user