From c6bdd2c56bab056599ddb015809fd7834e0b0a08 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Fri, 16 Dec 2016 12:08:43 -0800 Subject: [PATCH] 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 --- .../20161216.dashboard.ngram.01.sql | 15 +++++++++++++ .../20161216.dashboard.ngram.02.php | 21 +++++++++++++++++++ src/__phutil_library_map__.php | 6 ++++++ .../PhabricatorDashboardPanelEditEngine.php | 6 +++++- .../query/PhabricatorDashboardPanelQuery.php | 10 +++++++++ .../PhabricatorDashboardPanelSearchEngine.php | 8 +++++++ .../query/PhabricatorDashboardQuery.php | 10 +++++++++ .../PhabricatorDashboardSearchEngine.php | 8 +++++++ .../storage/PhabricatorDashboard.php | 15 +++++++++++-- .../storage/PhabricatorDashboardNgrams.php | 18 ++++++++++++++++ .../storage/PhabricatorDashboardPanel.php | 16 ++++++++++++-- .../PhabricatorDashboardPanelNgrams.php | 18 ++++++++++++++++ 12 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 resources/sql/autopatches/20161216.dashboard.ngram.01.sql create mode 100644 resources/sql/autopatches/20161216.dashboard.ngram.02.php create mode 100644 src/applications/dashboard/storage/PhabricatorDashboardNgrams.php create mode 100644 src/applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php diff --git a/resources/sql/autopatches/20161216.dashboard.ngram.01.sql b/resources/sql/autopatches/20161216.dashboard.ngram.01.sql new file mode 100644 index 0000000000..8fd237fe82 --- /dev/null +++ b/resources/sql/autopatches/20161216.dashboard.ngram.01.sql @@ -0,0 +1,15 @@ +CREATE TABLE {$NAMESPACE}_dashboard.dashboard_dashboard_ngrams ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + objectID INT UNSIGNED NOT NULL, + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, + KEY `key_object` (objectID), + KEY `key_ngram` (ngram, objectID) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; + +CREATE TABLE {$NAMESPACE}_dashboard.dashboard_dashboardpanel_ngrams ( + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + objectID INT UNSIGNED NOT NULL, + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, + KEY `key_object` (objectID), + KEY `key_ngram` (ngram, objectID) +) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT}; diff --git a/resources/sql/autopatches/20161216.dashboard.ngram.02.php b/resources/sql/autopatches/20161216.dashboard.ngram.02.php new file mode 100644 index 0000000000..a7abc99b23 --- /dev/null +++ b/resources/sql/autopatches/20161216.dashboard.ngram.02.php @@ -0,0 +1,21 @@ +getPHID(), + array( + 'force' => true, + )); +} + +$table_dbp = new PhabricatorDashboardPanel(); + +foreach (new LiskMigrationIterator($table_dbp) as $panel) { + PhabricatorSearchWorker::queueDocumentForIndexing( + $panel->getPHID(), + array( + 'force' => true, + )); +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 31fe6f0817..9b2b886ae9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2445,6 +2445,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php', 'PhabricatorDashboardManageController' => 'applications/dashboard/controller/PhabricatorDashboardManageController.php', 'PhabricatorDashboardMovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardMovePanelController.php', + 'PhabricatorDashboardNgrams' => 'applications/dashboard/storage/PhabricatorDashboardNgrams.php', 'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php', 'PhabricatorDashboardPanelArchiveController' => 'applications/dashboard/controller/PhabricatorDashboardPanelArchiveController.php', 'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php', @@ -2456,6 +2457,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditproController.php', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php', + 'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php', 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', 'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php', @@ -7381,6 +7383,7 @@ phutil_register_library_map(array( 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', 'PhabricatorProjectInterface', + 'PhabricatorNgramsInterface', ), 'PhabricatorDashboardAddPanelController' => 'PhabricatorDashboardController', 'PhabricatorDashboardApplication' => 'PhabricatorApplication', @@ -7399,6 +7402,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardListController' => 'PhabricatorDashboardController', 'PhabricatorDashboardManageController' => 'PhabricatorDashboardController', 'PhabricatorDashboardMovePanelController' => 'PhabricatorDashboardController', + 'PhabricatorDashboardNgrams' => 'PhabricatorSearchNgrams', 'PhabricatorDashboardPanel' => array( 'PhabricatorDashboardDAO', 'PhabricatorApplicationTransactionInterface', @@ -7406,6 +7410,7 @@ phutil_register_library_map(array( 'PhabricatorCustomFieldInterface', 'PhabricatorFlaggableInterface', 'PhabricatorDestructibleInterface', + 'PhabricatorNgramsInterface', ), 'PhabricatorDashboardPanelArchiveController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelCoreCustomField' => array( @@ -7420,6 +7425,7 @@ phutil_register_library_map(array( 'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', + 'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams', 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController', diff --git a/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php b/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php index 48940dde60..c9be8bf013 100644 --- a/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php +++ b/src/applications/dashboard/editor/PhabricatorDashboardPanelEditEngine.php @@ -28,12 +28,16 @@ final class PhabricatorDashboardPanelEditEngine return pht('Edit Dashboard Panels'); } + protected function supportsSearch() { + return true; + } + public function getSummaryText() { return pht('This engine is used to modify dashboard panels.'); } public function getEngineApplicationClass() { - return 'PhabricatorSearchApplication'; + return 'PhabricatorDashboardApplication'; } protected function newEditableObject() { diff --git a/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php b/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php index 6fbdb3d99c..ac72c9ce6f 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php +++ b/src/applications/dashboard/query/PhabricatorDashboardPanelQuery.php @@ -34,6 +34,12 @@ final class PhabricatorDashboardPanelQuery return $this; } + public function withNameNgrams($ngrams) { + return $this->withNgramsConstraint( + id(new PhabricatorDashboardPanelNgrams()), + $ngrams); + } + protected function loadPage() { return $this->loadStandardPage($this->newResultObject()); } @@ -95,4 +101,8 @@ final class PhabricatorDashboardPanelQuery return 'PhabricatorDashboardApplication'; } + protected function getPrimaryTableAlias() { + return 'dashboard_panel'; + } + } diff --git a/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php index d9fe25ab02..89e77997d8 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php @@ -38,12 +38,20 @@ final class PhabricatorDashboardPanelSearchEngine $query->withAuthorPHIDs($map['authorPHIDs']); } + if ($map['name'] !== null) { + $query->withNameNgrams($map['name']); + } + return $query; } protected function buildCustomSearchFields() { return array( + id(new PhabricatorSearchTextField()) + ->setLabel(pht('Name Contains')) + ->setKey('name') + ->setDescription(pht('Search for panels by name substring.')), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Authored By')) ->setKey('authorPHIDs') diff --git a/src/applications/dashboard/query/PhabricatorDashboardQuery.php b/src/applications/dashboard/query/PhabricatorDashboardQuery.php index a250d646d0..a54cfbc47c 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardQuery.php +++ b/src/applications/dashboard/query/PhabricatorDashboardQuery.php @@ -41,6 +41,12 @@ final class PhabricatorDashboardQuery return $this; } + public function withNameNgrams($ngrams) { + return $this->withNgramsConstraint( + id(new PhabricatorDashboardNgrams()), + $ngrams); + } + protected function loadPage() { return $this->loadStandardPage($this->newResultObject()); } @@ -141,4 +147,8 @@ final class PhabricatorDashboardQuery return 'PhabricatorDashboardApplication'; } + protected function getPrimaryTableAlias() { + return 'dashboard'; + } + } diff --git a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php index 389bbb6bdc..c6c6ab1233 100644 --- a/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php +++ b/src/applications/dashboard/query/PhabricatorDashboardSearchEngine.php @@ -18,6 +18,10 @@ final class PhabricatorDashboardSearchEngine protected function buildCustomSearchFields() { return array( + id(new PhabricatorSearchTextField()) + ->setLabel(pht('Name Contains')) + ->setKey('name') + ->setDescription(pht('Search for dashboards by name substring.')), id(new PhabricatorSearchDatasourceField()) ->setLabel(pht('Authored By')) ->setKey('authorPHIDs') @@ -82,6 +86,10 @@ final class PhabricatorDashboardSearchEngine $query->withAuthorPHIDs($map['authorPHIDs']); } + if ($map['name'] !== null) { + $query->withNameNgrams($map['name']); + } + return $query; } diff --git a/src/applications/dashboard/storage/PhabricatorDashboard.php b/src/applications/dashboard/storage/PhabricatorDashboard.php index abba22498f..b9e40a76f6 100644 --- a/src/applications/dashboard/storage/PhabricatorDashboard.php +++ b/src/applications/dashboard/storage/PhabricatorDashboard.php @@ -9,7 +9,8 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO PhabricatorPolicyInterface, PhabricatorFlaggableInterface, PhabricatorDestructibleInterface, - PhabricatorProjectInterface { + PhabricatorProjectInterface, + PhabricatorNgramsInterface { protected $name; protected $authorPHID; @@ -63,7 +64,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO 'layoutConfig' => self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( - 'name' => 'text255', + 'name' => 'sort255', 'status' => 'text32', 'icon' => 'text32', 'authorPHID' => 'phid', @@ -186,4 +187,14 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO } +/* -( PhabricatorNgramInterface )------------------------------------------ */ + + + public function newNgrams() { + return array( + id(new PhabricatorDashboardNgrams()) + ->setValue($this->getName()), + ); + } + } diff --git a/src/applications/dashboard/storage/PhabricatorDashboardNgrams.php b/src/applications/dashboard/storage/PhabricatorDashboardNgrams.php new file mode 100644 index 0000000000..7884ec43f9 --- /dev/null +++ b/src/applications/dashboard/storage/PhabricatorDashboardNgrams.php @@ -0,0 +1,18 @@ + self::SERIALIZATION_JSON, ), self::CONFIG_COLUMN_SCHEMA => array( - 'name' => 'text255', + 'name' => 'sort255', 'panelType' => 'text64', 'authorPHID' => 'phid', 'isArchived' => 'bool', @@ -197,4 +198,15 @@ final class PhabricatorDashboardPanel $this->saveTransaction(); } + +/* -( PhabricatorNgramInterface )------------------------------------------ */ + + + public function newNgrams() { + return array( + id(new PhabricatorDashboardPanelNgrams()) + ->setValue($this->getName()), + ); + } + } diff --git a/src/applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php b/src/applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php new file mode 100644 index 0000000000..536da8b751 --- /dev/null +++ b/src/applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php @@ -0,0 +1,18 @@ +