@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

Add Ngram support to Dashboards / Panels

Summary: Build ngram indexs, adds search by name capability.

Test Plan: Search for a dashboard by partial name, search for a panel by partial name.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

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

+146 -5
+15
resources/sql/autopatches/20161216.dashboard.ngram.01.sql
··· 1 + CREATE TABLE {$NAMESPACE}_dashboard.dashboard_dashboard_ngrams ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + objectID INT UNSIGNED NOT NULL, 4 + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, 5 + KEY `key_object` (objectID), 6 + KEY `key_ngram` (ngram, objectID) 7 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; 8 + 9 + CREATE TABLE {$NAMESPACE}_dashboard.dashboard_dashboardpanel_ngrams ( 10 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 11 + objectID INT UNSIGNED NOT NULL, 12 + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, 13 + KEY `key_object` (objectID), 14 + KEY `key_ngram` (ngram, objectID) 15 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+21
resources/sql/autopatches/20161216.dashboard.ngram.02.php
··· 1 + <?php 2 + 3 + $table_db = new PhabricatorDashboard(); 4 + 5 + foreach (new LiskMigrationIterator($table_db) as $dashboard) { 6 + PhabricatorSearchWorker::queueDocumentForIndexing( 7 + $dashboard->getPHID(), 8 + array( 9 + 'force' => true, 10 + )); 11 + } 12 + 13 + $table_dbp = new PhabricatorDashboardPanel(); 14 + 15 + foreach (new LiskMigrationIterator($table_dbp) as $panel) { 16 + PhabricatorSearchWorker::queueDocumentForIndexing( 17 + $panel->getPHID(), 18 + array( 19 + 'force' => true, 20 + )); 21 + }
+6
src/__phutil_library_map__.php
··· 2445 2445 'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php', 2446 2446 'PhabricatorDashboardManageController' => 'applications/dashboard/controller/PhabricatorDashboardManageController.php', 2447 2447 'PhabricatorDashboardMovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardMovePanelController.php', 2448 + 'PhabricatorDashboardNgrams' => 'applications/dashboard/storage/PhabricatorDashboardNgrams.php', 2448 2449 'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php', 2449 2450 'PhabricatorDashboardPanelArchiveController' => 'applications/dashboard/controller/PhabricatorDashboardPanelArchiveController.php', 2450 2451 'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php', ··· 2456 2457 'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditproController.php', 2457 2458 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 2458 2459 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php', 2460 + 'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php', 2459 2461 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 2460 2462 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', 2461 2463 'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php', ··· 7381 7383 'PhabricatorFlaggableInterface', 7382 7384 'PhabricatorDestructibleInterface', 7383 7385 'PhabricatorProjectInterface', 7386 + 'PhabricatorNgramsInterface', 7384 7387 ), 7385 7388 'PhabricatorDashboardAddPanelController' => 'PhabricatorDashboardController', 7386 7389 'PhabricatorDashboardApplication' => 'PhabricatorApplication', ··· 7399 7402 'PhabricatorDashboardListController' => 'PhabricatorDashboardController', 7400 7403 'PhabricatorDashboardManageController' => 'PhabricatorDashboardController', 7401 7404 'PhabricatorDashboardMovePanelController' => 'PhabricatorDashboardController', 7405 + 'PhabricatorDashboardNgrams' => 'PhabricatorSearchNgrams', 7402 7406 'PhabricatorDashboardPanel' => array( 7403 7407 'PhabricatorDashboardDAO', 7404 7408 'PhabricatorApplicationTransactionInterface', ··· 7406 7410 'PhabricatorCustomFieldInterface', 7407 7411 'PhabricatorFlaggableInterface', 7408 7412 'PhabricatorDestructibleInterface', 7413 + 'PhabricatorNgramsInterface', 7409 7414 ), 7410 7415 'PhabricatorDashboardPanelArchiveController' => 'PhabricatorDashboardController', 7411 7416 'PhabricatorDashboardPanelCoreCustomField' => array( ··· 7420 7425 'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController', 7421 7426 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 7422 7427 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', 7428 + 'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams', 7423 7429 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 7424 7430 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7425 7431 'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController',
+5 -1
src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php
··· 28 28 return pht('Edit Dashboard Panels'); 29 29 } 30 30 31 + protected function supportsSearch() { 32 + return true; 33 + } 34 + 31 35 public function getSummaryText() { 32 36 return pht('This engine is used to modify dashboard panels.'); 33 37 } 34 38 35 39 public function getEngineApplicationClass() { 36 - return 'PhabricatorSearchApplication'; 40 + return 'PhabricatorDashboardApplication'; 37 41 } 38 42 39 43 protected function newEditableObject() {
+10
src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php
··· 34 34 return $this; 35 35 } 36 36 37 + public function withNameNgrams($ngrams) { 38 + return $this->withNgramsConstraint( 39 + id(new PhabricatorDashboardPanelNgrams()), 40 + $ngrams); 41 + } 42 + 37 43 protected function loadPage() { 38 44 return $this->loadStandardPage($this->newResultObject()); 39 45 } ··· 93 99 94 100 public function getQueryApplicationClass() { 95 101 return 'PhabricatorDashboardApplication'; 102 + } 103 + 104 + protected function getPrimaryTableAlias() { 105 + return 'dashboard_panel'; 96 106 } 97 107 98 108 }
+8
src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php
··· 38 38 $query->withAuthorPHIDs($map['authorPHIDs']); 39 39 } 40 40 41 + if ($map['name'] !== null) { 42 + $query->withNameNgrams($map['name']); 43 + } 44 + 41 45 return $query; 42 46 } 43 47 44 48 protected function buildCustomSearchFields() { 45 49 46 50 return array( 51 + id(new PhabricatorSearchTextField()) 52 + ->setLabel(pht('Name Contains')) 53 + ->setKey('name') 54 + ->setDescription(pht('Search for panels by name substring.')), 47 55 id(new PhabricatorSearchDatasourceField()) 48 56 ->setLabel(pht('Authored By')) 49 57 ->setKey('authorPHIDs')
+10
src/applications/dashboard/query/PhabricatorDashboardQuery.php
··· 41 41 return $this; 42 42 } 43 43 44 + public function withNameNgrams($ngrams) { 45 + return $this->withNgramsConstraint( 46 + id(new PhabricatorDashboardNgrams()), 47 + $ngrams); 48 + } 49 + 44 50 protected function loadPage() { 45 51 return $this->loadStandardPage($this->newResultObject()); 46 52 } ··· 139 145 140 146 public function getQueryApplicationClass() { 141 147 return 'PhabricatorDashboardApplication'; 148 + } 149 + 150 + protected function getPrimaryTableAlias() { 151 + return 'dashboard'; 142 152 } 143 153 144 154 }
+8
src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php
··· 18 18 19 19 protected function buildCustomSearchFields() { 20 20 return array( 21 + id(new PhabricatorSearchTextField()) 22 + ->setLabel(pht('Name Contains')) 23 + ->setKey('name') 24 + ->setDescription(pht('Search for dashboards by name substring.')), 21 25 id(new PhabricatorSearchDatasourceField()) 22 26 ->setLabel(pht('Authored By')) 23 27 ->setKey('authorPHIDs') ··· 80 84 81 85 if ($map['authorPHIDs']) { 82 86 $query->withAuthorPHIDs($map['authorPHIDs']); 87 + } 88 + 89 + if ($map['name'] !== null) { 90 + $query->withNameNgrams($map['name']); 83 91 } 84 92 85 93 return $query;
+13 -2
src/applications/dashboard/storage/PhabricatorDashboard.php
··· 9 9 PhabricatorPolicyInterface, 10 10 PhabricatorFlaggableInterface, 11 11 PhabricatorDestructibleInterface, 12 - PhabricatorProjectInterface { 12 + PhabricatorProjectInterface, 13 + PhabricatorNgramsInterface { 13 14 14 15 protected $name; 15 16 protected $authorPHID; ··· 63 64 'layoutConfig' => self::SERIALIZATION_JSON, 64 65 ), 65 66 self::CONFIG_COLUMN_SCHEMA => array( 66 - 'name' => 'text255', 67 + 'name' => 'sort255', 67 68 'status' => 'text32', 68 69 'icon' => 'text32', 69 70 'authorPHID' => 'phid', ··· 185 186 $this->saveTransaction(); 186 187 } 187 188 189 + 190 + /* -( PhabricatorNgramInterface )------------------------------------------ */ 191 + 192 + 193 + public function newNgrams() { 194 + return array( 195 + id(new PhabricatorDashboardNgrams()) 196 + ->setValue($this->getName()), 197 + ); 198 + } 188 199 189 200 }
+18
src/applications/dashboard/storage/PhabricatorDashboardNgrams.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardNgrams 4 + extends PhabricatorSearchNgrams { 5 + 6 + public function getNgramKey() { 7 + return 'dashboard'; 8 + } 9 + 10 + public function getColumnName() { 11 + return 'name'; 12 + } 13 + 14 + public function getApplicationName() { 15 + return 'dashboard'; 16 + } 17 + 18 + }
+14 -2
src/applications/dashboard/storage/PhabricatorDashboardPanel.php
··· 10 10 PhabricatorPolicyInterface, 11 11 PhabricatorCustomFieldInterface, 12 12 PhabricatorFlaggableInterface, 13 - PhabricatorDestructibleInterface { 13 + PhabricatorDestructibleInterface, 14 + PhabricatorNgramsInterface { 14 15 15 16 protected $name; 16 17 protected $panelType; ··· 50 51 'properties' => self::SERIALIZATION_JSON, 51 52 ), 52 53 self::CONFIG_COLUMN_SCHEMA => array( 53 - 'name' => 'text255', 54 + 'name' => 'sort255', 54 55 'panelType' => 'text64', 55 56 'authorPHID' => 'phid', 56 57 'isArchived' => 'bool', ··· 195 196 $this->openTransaction(); 196 197 $this->delete(); 197 198 $this->saveTransaction(); 199 + } 200 + 201 + 202 + /* -( PhabricatorNgramInterface )------------------------------------------ */ 203 + 204 + 205 + public function newNgrams() { 206 + return array( 207 + id(new PhabricatorDashboardPanelNgrams()) 208 + ->setValue($this->getName()), 209 + ); 198 210 } 199 211 200 212 }
+18
src/applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php
··· 1 + <?php 2 + 3 + final class PhabricatorDashboardPanelNgrams 4 + extends PhabricatorSearchNgrams { 5 + 6 + public function getNgramKey() { 7 + return 'dashboardpanel'; 8 + } 9 + 10 + public function getColumnName() { 11 + return 'name'; 12 + } 13 + 14 + public function getApplicationName() { 15 + return 'dashboard'; 16 + } 17 + 18 + }