From f078fd98d79bb6344a10fbbc91b53e0de9abaae6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 27 Feb 2016 08:59:33 -0800 Subject: [PATCH] Support searching for Harbormater build plans by name substring Summary: Ref T10457. Allow build plans to be queried by name. Test Plan: - Searched for plans by name. - Renamed a plan, searched for new name. {F1133085} Reviewers: chad Reviewed By: chad Maniphest Tasks: T10457 Differential Revision: https://secure.phabricator.com/D15359 --- .../20160227.harbormaster.1.plann.sql | 7 +++++++ .../20160227.harbormaster.2.plani.php | 11 ++++++++++ src/__phutil_library_map__.php | 3 +++ .../editor/HarbormasterBuildPlanEditor.php | 4 ++++ .../query/HarbormasterBuildPlanQuery.php | 20 ++++++++++++++----- .../HarbormasterBuildPlanSearchEngine.php | 8 ++++++++ .../configuration/HarbormasterBuildPlan.php | 14 ++++++++++++- .../HarbormasterBuildPlanNameNgrams.php | 18 +++++++++++++++++ 8 files changed, 79 insertions(+), 6 deletions(-) create mode 100644 resources/sql/autopatches/20160227.harbormaster.1.plann.sql create mode 100644 resources/sql/autopatches/20160227.harbormaster.2.plani.php create mode 100644 src/applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php diff --git a/resources/sql/autopatches/20160227.harbormaster.1.plann.sql b/resources/sql/autopatches/20160227.harbormaster.1.plann.sql new file mode 100644 index 0000000000..4c0b4f48b3 --- /dev/null +++ b/resources/sql/autopatches/20160227.harbormaster.1.plann.sql @@ -0,0 +1,7 @@ +CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_buildplanname_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/20160227.harbormaster.2.plani.php b/resources/sql/autopatches/20160227.harbormaster.2.plani.php new file mode 100644 index 0000000000..6dea004c06 --- /dev/null +++ b/resources/sql/autopatches/20160227.harbormaster.2.plani.php @@ -0,0 +1,11 @@ +getPHID(), + array( + 'force' => true, + )); +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 0a60ce8330..ce5912410f 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1055,6 +1055,7 @@ phutil_register_library_map(array( 'HarbormasterBuildPlanDefaultViewCapability' => 'applications/harbormaster/capability/HarbormasterBuildPlanDefaultViewCapability.php', 'HarbormasterBuildPlanEditEngine' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php', 'HarbormasterBuildPlanEditor' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditor.php', + 'HarbormasterBuildPlanNameNgrams' => 'applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php', 'HarbormasterBuildPlanPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php', 'HarbormasterBuildPlanQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanQuery.php', 'HarbormasterBuildPlanSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php', @@ -5199,12 +5200,14 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'PhabricatorSubscribableInterface', + 'PhabricatorNgramsInterface', ), 'HarbormasterBuildPlanDatasource' => 'PhabricatorTypeaheadDatasource', 'HarbormasterBuildPlanDefaultEditCapability' => 'PhabricatorPolicyCapability', 'HarbormasterBuildPlanDefaultViewCapability' => 'PhabricatorPolicyCapability', 'HarbormasterBuildPlanEditEngine' => 'PhabricatorEditEngine', 'HarbormasterBuildPlanEditor' => 'PhabricatorApplicationTransactionEditor', + 'HarbormasterBuildPlanNameNgrams' => 'PhabricatorSearchNgrams', 'HarbormasterBuildPlanPHIDType' => 'PhabricatorPHIDType', 'HarbormasterBuildPlanQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'HarbormasterBuildPlanSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php b/src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php index 16fdd79f9e..71c9283ade 100644 --- a/src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php +++ b/src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php @@ -11,6 +11,10 @@ final class HarbormasterBuildPlanEditor return pht('Harbormaster Build Plans'); } + protected function supportsSearch() { + return true; + } + public function getTransactionTypes() { $types = parent::getTransactionTypes(); $types[] = HarbormasterBuildPlanTransaction::TYPE_NAME; diff --git a/src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php b/src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php index efa04b037b..4058325140 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php @@ -35,6 +35,12 @@ final class HarbormasterBuildPlanQuery return $this; } + public function withNameNgrams($ngrams) { + return $this->withNgramsConstraint( + new HarbormasterBuildPlanNameNgrams(), + $ngrams); + } + public function needBuildSteps($need) { $this->needBuildSteps = $need; return $this; @@ -74,41 +80,45 @@ final class HarbormasterBuildPlanQuery if ($this->ids !== null) { $where[] = qsprintf( $conn, - 'id IN (%Ld)', + 'plan.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, - 'phid IN (%Ls)', + 'plan.phid IN (%Ls)', $this->phids); } if ($this->statuses !== null) { $where[] = qsprintf( $conn, - 'planStatus IN (%Ls)', + 'plan.planStatus IN (%Ls)', $this->statuses); } if (strlen($this->datasourceQuery)) { $where[] = qsprintf( $conn, - 'name LIKE %>', + 'plan.name LIKE %>', $this->datasourceQuery); } if ($this->planAutoKeys !== null) { $where[] = qsprintf( $conn, - 'planAutoKey IN (%Ls)', + 'plan.planAutoKey IN (%Ls)', $this->planAutoKeys); } return $where; } + protected function getPrimaryTableAlias() { + return 'plan'; + } + public function getQueryApplicationClass() { return 'PhabricatorHarbormasterApplication'; } diff --git a/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php b/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php index 2a05cc21f3..cc345aa1fe 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php +++ b/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php @@ -17,6 +17,10 @@ final class HarbormasterBuildPlanSearchEngine protected function buildCustomSearchFields() { return array( + id(new PhabricatorSearchTextField()) + ->setLabel(pht('Name Contains')) + ->setKey('match') + ->setDescription(pht('Search for namespaces by name substring.')), id(new PhabricatorSearchCheckboxesField()) ->setLabel(pht('Status')) ->setKey('status') @@ -32,6 +36,10 @@ final class HarbormasterBuildPlanSearchEngine protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); + if ($map['match'] !== null) { + $query->withNameNgrams($map['match']); + } + if ($map['status']) { $query->withStatuses($map['status']); } diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php index 5ac9696813..31d84da7aa 100644 --- a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php @@ -7,7 +7,8 @@ final class HarbormasterBuildPlan extends HarbormasterDAO implements PhabricatorApplicationTransactionInterface, PhabricatorPolicyInterface, - PhabricatorSubscribableInterface { + PhabricatorSubscribableInterface, + PhabricatorNgramsInterface { protected $name; protected $planStatus; @@ -198,4 +199,15 @@ final class HarbormasterBuildPlan extends HarbormasterDAO return $messages; } + +/* -( PhabricatorNgramInterface )------------------------------------------ */ + + + public function newNgrams() { + return array( + id(new HarbormasterBuildPlanNameNgrams()) + ->setValue($this->getName()), + ); + } + } diff --git a/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php new file mode 100644 index 0000000000..e91daad8ce --- /dev/null +++ b/src/applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php @@ -0,0 +1,18 @@ +