From 01379958fa3d330fcb14ea329f835a7e7342f05e Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 3 Mar 2016 04:17:24 -0800 Subject: [PATCH] Allow Drydock blueprints to be searched by name Summary: Ref T10457. The ngram indexing seems to be working well; extend it into Drydock. Also clean up the list controller a little bit. Test Plan: - Ran migrations. - Searched for blueprints by name. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10457 Differential Revision: https://secure.phabricator.com/D15389 --- .../autopatches/20160303.drydock.1.bluen.sql | 7 +++++++ .../autopatches/20160303.drydock.2.bluei.php | 11 +++++++++++ src/__phutil_library_map__.php | 3 +++ .../DrydockBlueprintListController.php | 12 +++--------- .../drydock/editor/DrydockBlueprintEditor.php | 4 ++++ .../drydock/query/DrydockBlueprintQuery.php | 6 ++++++ .../query/DrydockBlueprintSearchEngine.php | 8 ++++++++ .../drydock/storage/DrydockBlueprint.php | 13 ++++++++++++- .../storage/DrydockBlueprintNameNgrams.php | 18 ++++++++++++++++++ 9 files changed, 72 insertions(+), 10 deletions(-) create mode 100644 resources/sql/autopatches/20160303.drydock.1.bluen.sql create mode 100644 resources/sql/autopatches/20160303.drydock.2.bluei.php create mode 100644 src/applications/drydock/storage/DrydockBlueprintNameNgrams.php diff --git a/resources/sql/autopatches/20160303.drydock.1.bluen.sql b/resources/sql/autopatches/20160303.drydock.1.bluen.sql new file mode 100644 index 0000000000..c0cbf90492 --- /dev/null +++ b/resources/sql/autopatches/20160303.drydock.1.bluen.sql @@ -0,0 +1,7 @@ +CREATE TABLE {$NAMESPACE}_drydock.drydock_blueprintname_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/20160303.drydock.2.bluei.php b/resources/sql/autopatches/20160303.drydock.2.bluei.php new file mode 100644 index 0000000000..c0b68c2262 --- /dev/null +++ b/resources/sql/autopatches/20160303.drydock.2.bluei.php @@ -0,0 +1,11 @@ +getPHID(), + array( + 'force' => true, + )); +} diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 32a5f5cdf1..5750dee24e 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -876,6 +876,7 @@ phutil_register_library_map(array( 'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php', 'DrydockBlueprintImplementationTestCase' => 'applications/drydock/blueprint/__tests__/DrydockBlueprintImplementationTestCase.php', 'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php', + 'DrydockBlueprintNameNgrams' => 'applications/drydock/storage/DrydockBlueprintNameNgrams.php', 'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php', 'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php', 'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php', @@ -4972,6 +4973,7 @@ phutil_register_library_map(array( 'PhabricatorApplicationTransactionInterface', 'PhabricatorPolicyInterface', 'PhabricatorCustomFieldInterface', + 'PhabricatorNgramsInterface', ), 'DrydockBlueprintController' => 'DrydockController', 'DrydockBlueprintCoreCustomField' => array( @@ -4987,6 +4989,7 @@ phutil_register_library_map(array( 'DrydockBlueprintImplementation' => 'Phobject', 'DrydockBlueprintImplementationTestCase' => 'PhabricatorTestCase', 'DrydockBlueprintListController' => 'DrydockBlueprintController', + 'DrydockBlueprintNameNgrams' => 'PhabricatorSearchNgrams', 'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType', 'DrydockBlueprintQuery' => 'DrydockQuery', 'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine', diff --git a/src/applications/drydock/controller/DrydockBlueprintListController.php b/src/applications/drydock/controller/DrydockBlueprintListController.php index ff09f19ff8..98757c99b0 100644 --- a/src/applications/drydock/controller/DrydockBlueprintListController.php +++ b/src/applications/drydock/controller/DrydockBlueprintListController.php @@ -7,15 +7,9 @@ final class DrydockBlueprintListController extends DrydockBlueprintController { } public function handleRequest(AphrontRequest $request) { - $querykey = $request->getURIData('queryKey'); - - $request = $this->getRequest(); - $controller = id(new PhabricatorApplicationSearchController()) - ->setQueryKey($querykey) - ->setSearchEngine(new DrydockBlueprintSearchEngine()) - ->setNavigation($this->buildSideNavView()); - - return $this->delegateToController($controller); + return id(new DrydockBlueprintSearchEngine()) + ->setController($this) + ->buildResponse(); } protected function buildApplicationCrumbs() { diff --git a/src/applications/drydock/editor/DrydockBlueprintEditor.php b/src/applications/drydock/editor/DrydockBlueprintEditor.php index b5fd584945..315f91cd5c 100644 --- a/src/applications/drydock/editor/DrydockBlueprintEditor.php +++ b/src/applications/drydock/editor/DrydockBlueprintEditor.php @@ -11,6 +11,10 @@ final class DrydockBlueprintEditor return pht('Drydock Blueprints'); } + protected function supportsSearch() { + return true; + } + public function getTransactionTypes() { $types = parent::getTransactionTypes(); diff --git a/src/applications/drydock/query/DrydockBlueprintQuery.php b/src/applications/drydock/query/DrydockBlueprintQuery.php index 169e47b4f7..6c92927bb8 100644 --- a/src/applications/drydock/query/DrydockBlueprintQuery.php +++ b/src/applications/drydock/query/DrydockBlueprintQuery.php @@ -39,6 +39,12 @@ final class DrydockBlueprintQuery extends DrydockQuery { return $this; } + public function withNameNgrams($ngrams) { + return $this->withNgramsConstraint( + new DrydockBlueprintNameNgrams(), + $ngrams); + } + public function newResultObject() { return new DrydockBlueprint(); } diff --git a/src/applications/drydock/query/DrydockBlueprintSearchEngine.php b/src/applications/drydock/query/DrydockBlueprintSearchEngine.php index 64859649df..bb7bd02cc9 100644 --- a/src/applications/drydock/query/DrydockBlueprintSearchEngine.php +++ b/src/applications/drydock/query/DrydockBlueprintSearchEngine.php @@ -18,6 +18,10 @@ final class DrydockBlueprintSearchEngine protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); + if ($map['match'] !== null) { + $query->withNameNgrams($map['match']); + } + if ($map['isDisabled'] !== null) { $query->withDisabled($map['isDisabled']); } @@ -27,6 +31,10 @@ final class DrydockBlueprintSearchEngine protected function buildCustomSearchFields() { return array( + id(new PhabricatorSearchTextField()) + ->setLabel(pht('Name Contains')) + ->setKey('match') + ->setDescription(pht('Search for blueprints by name substring.')), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Disabled')) ->setKey('isDisabled') diff --git a/src/applications/drydock/storage/DrydockBlueprint.php b/src/applications/drydock/storage/DrydockBlueprint.php index 4bc3dbe86d..dd50c29820 100644 --- a/src/applications/drydock/storage/DrydockBlueprint.php +++ b/src/applications/drydock/storage/DrydockBlueprint.php @@ -8,7 +8,8 @@ final class DrydockBlueprint extends DrydockDAO implements PhabricatorApplicationTransactionInterface, PhabricatorPolicyInterface, - PhabricatorCustomFieldInterface { + PhabricatorCustomFieldInterface, + PhabricatorNgramsInterface { protected $className; protected $blueprintName; @@ -343,4 +344,14 @@ final class DrydockBlueprint extends DrydockDAO } +/* -( PhabricatorNgramInterface )------------------------------------------ */ + + + public function newNgrams() { + return array( + id(new DrydockBlueprintNameNgrams()) + ->setValue($this->getBlueprintName()), + ); + } + } diff --git a/src/applications/drydock/storage/DrydockBlueprintNameNgrams.php b/src/applications/drydock/storage/DrydockBlueprintNameNgrams.php new file mode 100644 index 0000000000..f140e11ca9 --- /dev/null +++ b/src/applications/drydock/storage/DrydockBlueprintNameNgrams.php @@ -0,0 +1,18 @@ +