@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create and populate a stopwords table for InnoDB fulltext indexes to use in the future

Summary:
Ref T11741. InnoDB uses a stopwords table instead of a stopwords file.

During `storage upgrade`, synchronize the table from the stopwords file on disk.

Test Plan:
- Ran `storage upgrade`.
- Ran `select * from stopwords`, saw stopwords.
- Added some garbage to the table.
- Ran `storage upgrade`, saw it remove it.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11741

Differential Revision: https://secure.phabricator.com/D16940

+66
+3
resources/sql/autopatches/20161124.search.01.stopwords.sql
··· 1 + CREATE TABLE {$NAMESPACE}_search.stopwords ( 2 + value VARCHAR(32) NOT NULL COLLATE {$COLLATE_SORT} 3 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+8
src/applications/search/storage/PhabricatorSearchSchemaSpec.php
··· 5 5 6 6 public function buildSchemata() { 7 7 $this->buildEdgeSchemata(new PhabricatorProfilePanelConfiguration()); 8 + 9 + $this->buildRawSchema( 10 + 'search', 11 + PhabricatorSearchDocument::STOPWORDS_TABLE, 12 + array( 13 + 'value' => 'sort32', 14 + ), 15 + array()); 8 16 } 9 17 10 18 }
+2
src/applications/search/storage/document/PhabricatorSearchDocument.php
··· 7 7 protected $documentCreated; 8 8 protected $documentModified; 9 9 10 + const STOPWORDS_TABLE = 'stopwords'; 11 + 10 12 protected function getConfiguration() { 11 13 return array( 12 14 self::CONFIG_TIMESTAMPS => false,
+53
src/infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php
··· 77 77 78 78 $this->upgradeSchemata($apis, $apply_only, $no_quickstart, $init_only); 79 79 80 + if ($apply_only || $init_only) { 81 + echo tsprintf( 82 + "%s\n", 83 + pht('Declining to synchronize static tables.')); 84 + } else { 85 + echo tsprintf( 86 + "%s\n", 87 + pht('Synchronizing static tables...')); 88 + $this->synchronizeSchemata(); 89 + } 90 + 80 91 if ($no_adjust || $init_only || $apply_only) { 81 92 $console->writeOut( 82 93 "%s\n", ··· 92 103 93 104 return 0; 94 105 } 106 + 107 + private function synchronizeSchemata() { 108 + // Synchronize the InnoDB fulltext stopwords table from the stopwords file 109 + // on disk. 110 + 111 + $table = new PhabricatorSearchDocument(); 112 + $conn = $table->establishConnection('w'); 113 + $table_ref = PhabricatorSearchDocument::STOPWORDS_TABLE; 114 + 115 + $stopwords_database = queryfx_all( 116 + $conn, 117 + 'SELECT value FROM %T', 118 + $table_ref); 119 + $stopwords_database = ipull($stopwords_database, 'value', 'value'); 120 + 121 + $stopwords_path = phutil_get_library_root('phabricator'); 122 + $stopwords_path = $stopwords_path.'/../resources/sql/stopwords.txt'; 123 + $stopwords_file = Filesystem::readFile($stopwords_path); 124 + $stopwords_file = phutil_split_lines($stopwords_file, false); 125 + $stopwords_file = array_fuse($stopwords_file); 126 + 127 + $rem_words = array_diff_key($stopwords_database, $stopwords_file); 128 + if ($rem_words) { 129 + queryfx( 130 + $conn, 131 + 'DELETE FROM %T WHERE value IN (%Ls)', 132 + $table_ref, 133 + $rem_words); 134 + } 135 + 136 + $add_words = array_diff_key($stopwords_file, $stopwords_database); 137 + if ($add_words) { 138 + foreach ($add_words as $word) { 139 + queryfx( 140 + $conn, 141 + 'INSERT IGNORE INTO %T (value) VALUES (%s)', 142 + $table_ref, 143 + $word); 144 + } 145 + } 146 + } 147 + 95 148 96 149 }