1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02: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',
'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',

View file

@ -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() {

View file

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

View file

@ -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')

View file

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

View file

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

View file

@ -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()),
);
}
}

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,
PhabricatorCustomFieldInterface,
PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface {
PhabricatorDestructibleInterface,
PhabricatorNgramsInterface {
protected $name;
protected $panelType;
@ -50,7 +51,7 @@ final class PhabricatorDashboardPanel
'properties' => 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()),
);
}
}

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