1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +01:00

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
This commit is contained in:
Chad Little 2016-12-16 12:08:43 -08:00
parent 895cdaca5d
commit c6bdd2c56b
12 changed files with 146 additions and 5 deletions

View file

@ -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};

View file

@ -0,0 +1,21 @@
<?php
$table_db = new PhabricatorDashboard();
foreach (new LiskMigrationIterator($table_db) as $dashboard) {
PhabricatorSearchWorker::queueDocumentForIndexing(
$dashboard->getPHID(),
array(
'force' => true,
));
}
$table_dbp = new PhabricatorDashboardPanel();
foreach (new LiskMigrationIterator($table_dbp) as $panel) {
PhabricatorSearchWorker::queueDocumentForIndexing(
$panel->getPHID(),
array(
'force' => true,
));
}

View file

@ -2445,6 +2445,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php', 'PhabricatorDashboardListController' => 'applications/dashboard/controller/PhabricatorDashboardListController.php',
'PhabricatorDashboardManageController' => 'applications/dashboard/controller/PhabricatorDashboardManageController.php', 'PhabricatorDashboardManageController' => 'applications/dashboard/controller/PhabricatorDashboardManageController.php',
'PhabricatorDashboardMovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardMovePanelController.php', 'PhabricatorDashboardMovePanelController' => 'applications/dashboard/controller/PhabricatorDashboardMovePanelController.php',
'PhabricatorDashboardNgrams' => 'applications/dashboard/storage/PhabricatorDashboardNgrams.php',
'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php', 'PhabricatorDashboardPanel' => 'applications/dashboard/storage/PhabricatorDashboardPanel.php',
'PhabricatorDashboardPanelArchiveController' => 'applications/dashboard/controller/PhabricatorDashboardPanelArchiveController.php', 'PhabricatorDashboardPanelArchiveController' => 'applications/dashboard/controller/PhabricatorDashboardPanelArchiveController.php',
'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php', 'PhabricatorDashboardPanelCoreCustomField' => 'applications/dashboard/customfield/PhabricatorDashboardPanelCoreCustomField.php',
@ -2456,6 +2457,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditproController.php', 'PhabricatorDashboardPanelEditproController' => 'applications/dashboard/controller/PhabricatorDashboardPanelEditproController.php',
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'applications/dashboard/edge/PhabricatorDashboardPanelHasDashboardEdgeType.php',
'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php', 'PhabricatorDashboardPanelListController' => 'applications/dashboard/controller/PhabricatorDashboardPanelListController.php',
'PhabricatorDashboardPanelNgrams' => 'applications/dashboard/storage/PhabricatorDashboardPanelNgrams.php',
'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php', 'PhabricatorDashboardPanelPHIDType' => 'applications/dashboard/phid/PhabricatorDashboardPanelPHIDType.php',
'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php', 'PhabricatorDashboardPanelQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelQuery.php',
'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php', 'PhabricatorDashboardPanelRenderController' => 'applications/dashboard/controller/PhabricatorDashboardPanelRenderController.php',
@ -7381,6 +7383,7 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface', 'PhabricatorFlaggableInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
'PhabricatorProjectInterface', 'PhabricatorProjectInterface',
'PhabricatorNgramsInterface',
), ),
'PhabricatorDashboardAddPanelController' => 'PhabricatorDashboardController', 'PhabricatorDashboardAddPanelController' => 'PhabricatorDashboardController',
'PhabricatorDashboardApplication' => 'PhabricatorApplication', 'PhabricatorDashboardApplication' => 'PhabricatorApplication',
@ -7399,6 +7402,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardListController' => 'PhabricatorDashboardController', 'PhabricatorDashboardListController' => 'PhabricatorDashboardController',
'PhabricatorDashboardManageController' => 'PhabricatorDashboardController', 'PhabricatorDashboardManageController' => 'PhabricatorDashboardController',
'PhabricatorDashboardMovePanelController' => 'PhabricatorDashboardController', 'PhabricatorDashboardMovePanelController' => 'PhabricatorDashboardController',
'PhabricatorDashboardNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorDashboardPanel' => array( 'PhabricatorDashboardPanel' => array(
'PhabricatorDashboardDAO', 'PhabricatorDashboardDAO',
'PhabricatorApplicationTransactionInterface', 'PhabricatorApplicationTransactionInterface',
@ -7406,6 +7410,7 @@ phutil_register_library_map(array(
'PhabricatorCustomFieldInterface', 'PhabricatorCustomFieldInterface',
'PhabricatorFlaggableInterface', 'PhabricatorFlaggableInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
'PhabricatorNgramsInterface',
), ),
'PhabricatorDashboardPanelArchiveController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelArchiveController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPanelCoreCustomField' => array( 'PhabricatorDashboardPanelCoreCustomField' => array(
@ -7420,6 +7425,7 @@ phutil_register_library_map(array(
'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelEditproController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType', 'PhabricatorDashboardPanelHasDashboardEdgeType' => 'PhabricatorEdgeType',
'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelListController' => 'PhabricatorDashboardController',
'PhabricatorDashboardPanelNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType', 'PhabricatorDashboardPanelPHIDType' => 'PhabricatorPHIDType',
'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhabricatorDashboardPanelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController', 'PhabricatorDashboardPanelRenderController' => 'PhabricatorDashboardController',

View file

@ -28,12 +28,16 @@ final class PhabricatorDashboardPanelEditEngine
return pht('Edit Dashboard Panels'); return pht('Edit Dashboard Panels');
} }
protected function supportsSearch() {
return true;
}
public function getSummaryText() { public function getSummaryText() {
return pht('This engine is used to modify dashboard panels.'); return pht('This engine is used to modify dashboard panels.');
} }
public function getEngineApplicationClass() { public function getEngineApplicationClass() {
return 'PhabricatorSearchApplication'; return 'PhabricatorDashboardApplication';
} }
protected function newEditableObject() { protected function newEditableObject() {

View file

@ -34,6 +34,12 @@ final class PhabricatorDashboardPanelQuery
return $this; return $this;
} }
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
id(new PhabricatorDashboardPanelNgrams()),
$ngrams);
}
protected function loadPage() { protected function loadPage() {
return $this->loadStandardPage($this->newResultObject()); return $this->loadStandardPage($this->newResultObject());
} }
@ -95,4 +101,8 @@ final class PhabricatorDashboardPanelQuery
return 'PhabricatorDashboardApplication'; return 'PhabricatorDashboardApplication';
} }
protected function getPrimaryTableAlias() {
return 'dashboard_panel';
}
} }

View file

@ -38,12 +38,20 @@ final class PhabricatorDashboardPanelSearchEngine
$query->withAuthorPHIDs($map['authorPHIDs']); $query->withAuthorPHIDs($map['authorPHIDs']);
} }
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
return $query; return $query;
} }
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
return array( return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for panels by name substring.')),
id(new PhabricatorSearchDatasourceField()) id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Authored By')) ->setLabel(pht('Authored By'))
->setKey('authorPHIDs') ->setKey('authorPHIDs')

View file

@ -41,6 +41,12 @@ final class PhabricatorDashboardQuery
return $this; return $this;
} }
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
id(new PhabricatorDashboardNgrams()),
$ngrams);
}
protected function loadPage() { protected function loadPage() {
return $this->loadStandardPage($this->newResultObject()); return $this->loadStandardPage($this->newResultObject());
} }
@ -141,4 +147,8 @@ final class PhabricatorDashboardQuery
return 'PhabricatorDashboardApplication'; return 'PhabricatorDashboardApplication';
} }
protected function getPrimaryTableAlias() {
return 'dashboard';
}
} }

View file

@ -18,6 +18,10 @@ final class PhabricatorDashboardSearchEngine
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
return array( return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for dashboards by name substring.')),
id(new PhabricatorSearchDatasourceField()) id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Authored By')) ->setLabel(pht('Authored By'))
->setKey('authorPHIDs') ->setKey('authorPHIDs')
@ -82,6 +86,10 @@ final class PhabricatorDashboardSearchEngine
$query->withAuthorPHIDs($map['authorPHIDs']); $query->withAuthorPHIDs($map['authorPHIDs']);
} }
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
return $query; return $query;
} }

View file

@ -9,7 +9,8 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorFlaggableInterface, PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorProjectInterface { PhabricatorProjectInterface,
PhabricatorNgramsInterface {
protected $name; protected $name;
protected $authorPHID; protected $authorPHID;
@ -63,7 +64,7 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
'layoutConfig' => self::SERIALIZATION_JSON, 'layoutConfig' => self::SERIALIZATION_JSON,
), ),
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255', 'name' => 'sort255',
'status' => 'text32', 'status' => 'text32',
'icon' => 'text32', 'icon' => 'text32',
'authorPHID' => 'phid', 'authorPHID' => 'phid',
@ -186,4 +187,14 @@ final class PhabricatorDashboard extends PhabricatorDashboardDAO
} }
/* -( PhabricatorNgramInterface )------------------------------------------ */
public function newNgrams() {
return array(
id(new PhabricatorDashboardNgrams())
->setValue($this->getName()),
);
}
} }

View file

@ -0,0 +1,18 @@
<?php
final class PhabricatorDashboardNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'dashboard';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'dashboard';
}
}

View file

@ -10,7 +10,8 @@ final class PhabricatorDashboardPanel
PhabricatorPolicyInterface, PhabricatorPolicyInterface,
PhabricatorCustomFieldInterface, PhabricatorCustomFieldInterface,
PhabricatorFlaggableInterface, PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface { PhabricatorDestructibleInterface,
PhabricatorNgramsInterface {
protected $name; protected $name;
protected $panelType; protected $panelType;
@ -50,7 +51,7 @@ final class PhabricatorDashboardPanel
'properties' => self::SERIALIZATION_JSON, 'properties' => self::SERIALIZATION_JSON,
), ),
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255', 'name' => 'sort255',
'panelType' => 'text64', 'panelType' => 'text64',
'authorPHID' => 'phid', 'authorPHID' => 'phid',
'isArchived' => 'bool', 'isArchived' => 'bool',
@ -197,4 +198,15 @@ final class PhabricatorDashboardPanel
$this->saveTransaction(); $this->saveTransaction();
} }
/* -( PhabricatorNgramInterface )------------------------------------------ */
public function newNgrams() {
return array(
id(new PhabricatorDashboardPanelNgrams())
->setValue($this->getName()),
);
}
} }

View file

@ -0,0 +1,18 @@
<?php
final class PhabricatorDashboardPanelNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'dashboardpanel';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'dashboard';
}
}