2017-04-07 40 views

回答

0

全文搜索仅在MyISAM中提供。这是MyISAM对InnoDB的主要优势之一。相关:https://dba.stackexchange.com/questions/1/what-are-the-main-differences-between-innodb-and-myisam

+1

是,InnoDB的不支持它,直到MySQL的V5.6。但是,MySQL版本高于5.6。它确实支持全文搜索。 – Vishal

+1

我希望所有表在InnoDB中的原因是它可能会导致AWS上的自动备份问题。 http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_WorkingWithAutomatedBackups.html#Overview.BackupDeviceRestrictions – Vishal

5

正如您已经指出InnoDB支持从版本MySQL 5.6开始的全文搜索,但随框架附带的MySQLSchemaManager阻止您将InnoDB用于定义具有全文索引的表。也许你可以在GitHub上提出一个问题。你可以(通过扩展MySQLSchemaManager和压倒一切的alterTable())创建没有此限制自己SchemaManager:

# Compare this to https://github.com/silverstripe/silverstripe-framework/blob/3.5/model/connect/MySQLSchemaManager.php#L100 
class MyCustomSchemaManager extends MySQLSchemaManager 
{ 

    public function alterTable($tableName, $newFields = null, $newIndexes = null, $alteredFields = null, 
           $alteredIndexes = null, $alteredOptions = null, $advancedOptions = null 
    ) { 
     if ($this->isView($tableName)) { 
      $this->alterationMessage(
       sprintf("Table %s not changed as it is a view", $tableName), 
       "changed" 
      ); 
      return; 
     } 
     $alterList = array(); 

     if ($newFields) { 
      foreach ($newFields as $k => $v) { 
       $alterList[] .= "ADD \"$k\" $v"; 
      } 
     } 
     if ($newIndexes) { 
      foreach ($newIndexes as $k => $v) { 
       $alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v); 
      } 
     } 
     if ($alteredFields) { 
      foreach ($alteredFields as $k => $v) { 
       $alterList[] .= "CHANGE \"$k\" \"$k\" $v"; 
      } 
     } 
     if ($alteredIndexes) { 
      foreach ($alteredIndexes as $k => $v) { 
       $alterList[] .= "DROP INDEX \"$k\""; 
       $alterList[] .= "ADD " . $this->getIndexSqlDefinition($k, $v); 
      } 
     } 

     $dbID = self::ID; 
     if ($alteredOptions && isset($alteredOptions[$dbID])) { 
      $this->query(sprintf("ALTER TABLE \"%s\" %s", $tableName, $alteredOptions[$dbID])); 
      $this->alterationMessage(
       sprintf("Table %s options changed: %s", $tableName, $alteredOptions[$dbID]), 
       "changed" 
      ); 
     } 

     $alterations = implode(",\n", $alterList); 
     $this->query("ALTER TABLE \"$tableName\" $alterations"); 
    } 

} 

然后你可以使用Injector使用您的自定义类:

# Config.yml 
Injector: 
    MySQLSchemaManager: 
    class: MyCustomSchemaManager 

您现在应该能够使用静态create_table_options强制InnoDB引擎,并通过indexes静态创建全文索引。

例子:

# SomePage.php  

/** 
* Force InnoDB database engine. 
* 
* @var array 
*/ 
private static $create_table_options = [ 
    'MySQLDatabase' => 'ENGINE=InnoDB' 
]; 

/** 
* Define what fulltext indexes to create. 
* 
* @var array 
*/ 
private static $indexes = [ 
    'SearchFields' => [ 
     'type' => 'fulltext', 
     'name' => 'SearchFields', 
     'value' => '"MyField", "Tags"', 
    ] 
];