From 48625da04b8ab5865c31aef38033b94bf8cfa983 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sun, 18 Sep 2011 18:28:44 -0400 Subject: [PATCH] Automatically add or drop fulltext indexes --- classes/Notice.php | 8 +++++++- classes/Profile.php | 10 +++++++++- lib/schema.php | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index a38f54f050..ce6464c157 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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) diff --git a/classes/Profile.php b/classes/Profile.php index 8cea91ece6..b8178e9b66 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -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) diff --git a/lib/schema.php b/lib/schema.php index e188037e68..92555499ba 100644 --- a/lib/schema.php +++ b/lib/schema.php @@ -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; } -- 2.39.2