Added fulltext index support for PostgreSQL
authorMarcel Werk <burntime@woltlab.com>
Mon, 2 Jan 2012 18:35:21 +0000 (19:35 +0100)
committerMarcel Werk <burntime@woltlab.com>
Mon, 2 Jan 2012 18:35:21 +0000 (19:35 +0100)
wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php

index c9600ba11ef26e1558267cb81ee2984d64e141ff..576bf85666b6919014d855889f58344aaff5609d 100644 (file)
@@ -220,24 +220,25 @@ class PostgreSQLDatabaseEditor extends DatabaseEditor {
         * @see wcf\system\database\editor\DatabaseEditor::addIndex()
         */
        public function addIndex($tableName, $indexName, $indexData) {
+               if (empty($indexName)) {
+                       // create index name
+                       // TODO: solve naming conflicts
+                       $columns = ArrayUtil::trim(explode(',', $indexData['columns']));
+                       $indexName = $tableName.'_'.(!empty($columns[0]) ? $columns[0] : 'generic').'_key';
+               }
+               else {
+                       $indexName = $tableName.'_'.$indexName.'_key';
+               }
+               
+               $sql = '';
                if ($indexData['type'] == 'FULLTEXT') {
-                       // TODO: implement fulltext search in postgresql
+                       $sql = "CREATE INDEX ".$indexName." ON ".$tableName." USING gin(to_tsvector('english', \"".implode('" || \' \' || "', explode(',', $indexData['columns']))."\"))";
                }
                else {
-                       if (empty($indexName)) {
-                               // create index name
-                               // TODO: solve naming conflicts
-                               $columns = ArrayUtil::trim(explode(',', $indexData['columns']));
-                               $indexName = $tableName.'_'.(!empty($columns[0]) ? $columns[0] : 'generic').'_key';
-                       }
-                       else {
-                               $indexName = $tableName.'_'.$indexName.'_key';
-                       }
-                       
                        $sql = "CREATE ".($indexData['type'] == 'UNIQUE' ? "UNIQUE " : "")."INDEX ".$indexName." ON ".$tableName." (".$indexData['columns'].")";
-                       $statement = $this->dbObj->prepareStatement($sql);
-                       $statement->execute();
                }
+               $statement = $this->dbObj->prepareStatement($sql);
+               $statement->execute();
        }
        
        /**