Automatically add or drop fulltext indexes

This commit is contained in:
Evan Prodromou 2011-09-18 18:28:44 -04:00
parent 5b0192a8ac
commit 48625da04b
3 changed files with 21 additions and 2 deletions

View File

@ -87,7 +87,7 @@ class Notice extends Managed_DataObject
public static function schemaDef()
{
return array(
$def = array(
'fields' => array(
'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'who made the update'),
@ -129,6 +129,12 @@ class Notice extends Managed_DataObject
'notice_repeatof_idx' => array('repeat_of'),
)
);
if (common_config('search', 'type') == 'fulltext') {
$def['fulltext indexes'] = array('content' => array('content'));
}
return $def;
}
function multiGet($kc, $kvs, $skipNulls=true)

View File

@ -51,7 +51,7 @@ class Profile extends Managed_DataObject
public static function schemaDef()
{
return array(
$def = array(
'description' => 'local and remote users have profiles',
'fields' => array(
'id' => array('type' => 'serial', 'not null' => true, 'description' => 'unique identifier'),
@ -74,6 +74,14 @@ class Profile extends Managed_DataObject
'profile_nickname_idx' => array('nickname'),
)
);
// Add a fulltext index
if (common_config('search', 'type') == 'fulltext') {
$def['fulltext indexes'] = array('nickname' => array('nickname', 'fullname', 'location', 'bio', 'homepage'));
}
return $def;
}
function multiGet($keyCol, $keyVals, $skipNulls=true)

View File

@ -630,6 +630,11 @@ class Schema
$this->appendCreateIndex($statements, $tableName, $indexName, $def['indexes'][$indexName]);
}
foreach ($fulltext['mod'] + $fulltext['add'] as $indexName) {
$colDef = $def['fulltext indexes'][$indexName];
$this->appendCreateFulltextIndex($statements, $tableName, $indexName, $colDef);
}
return $statements;
}