Changed the behaviour of fulltext indices for PostgreSQL
authorMarcel Werk <burntime@woltlab.com>
Tue, 26 Jun 2012 11:52:39 +0000 (13:52 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 26 Jun 2012 11:52:39 +0000 (13:52 +0200)
wcfsetup/install/files/lib/system/database/editor/PostgreSQLDatabaseEditor.class.php

index bdc05e6dc0097e499178e5a5a05d48f70f6fed51..973b7d4fcb3734d39ceaf832487777279ba048b4 100644 (file)
@@ -238,13 +238,36 @@ class PostgreSQLDatabaseEditor extends DatabaseEditor {
                }
                
                if ($indexData['type'] == 'FULLTEXT') {
-                       $sql = "CREATE INDEX ".$indexName." ON ".$tableName." USING gin(to_tsvector('english', \"".implode('" || \' \' || "', $columns)."\"))";
+                       // add new column for fulltext index
+                       $sql = "ALTER TABLE ".$tableName." ADD COLUMN ".$indexName." tsvector";
+                       $statement = $this->dbObj->prepareStatement($sql);
+                       $statement->execute();
+                       
+                       // add gin index
+                       $sql = "CREATE INDEX ".$tableName."_".$indexName."_fulltext_key ON ".$tableName." USING gin(".$indexName.")";
+                       $statement = $this->dbObj->prepareStatement($sql);
+                       $statement->execute();
+                       
+                       // update fulltext index
+                       $sql = "UPDATE  ".$tableName."
+                               SET     ".$indexName." = to_tsvector('english', \"".implode('" || \' \' || "', $columns)."\")";
+                       $statement = $this->dbObj->prepareStatement($sql);
+                       $statement->execute();
+                       
+                       // add trigger
+                       $sql = "CREATE TRIGGER          ".$tableName."_".$indexName."_trigger
+                               BEFORE INSERT OR UPDATE
+                               ON                      ".$tableName."
+                               FOR EACH ROW EXECUTE PROCEDURE
+                               tsvector_update_trigger(".$indexName.", 'pg_catalog.english', ".implode(', ', $columns).");";
+                       $statement = $this->dbObj->prepareStatement($sql);
+                       $statement->execute();
                }
                else {
                        $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();
        }
        
        /**