@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

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

+72 -10
+7
resources/sql/autopatches/20160303.drydock.1.bluen.sql
··· 1 + CREATE TABLE {$NAMESPACE}_drydock.drydock_blueprintname_ngrams ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + objectID INT UNSIGNED NOT NULL, 4 + ngram CHAR(3) NOT NULL COLLATE {$COLLATE_TEXT}, 5 + KEY `key_object` (objectID), 6 + KEY `key_ngram` (ngram, objectID) 7 + ) ENGINE=InnoDB, COLLATE {$COLLATE_TEXT};
+11
resources/sql/autopatches/20160303.drydock.2.bluei.php
··· 1 + <?php 2 + 3 + $table = new DrydockBlueprint(); 4 + 5 + foreach (new LiskMigrationIterator($table) as $blueprint) { 6 + PhabricatorSearchWorker::queueDocumentForIndexing( 7 + $blueprint->getPHID(), 8 + array( 9 + 'force' => true, 10 + )); 11 + }
+3
src/__phutil_library_map__.php
··· 876 876 'DrydockBlueprintImplementation' => 'applications/drydock/blueprint/DrydockBlueprintImplementation.php', 877 877 'DrydockBlueprintImplementationTestCase' => 'applications/drydock/blueprint/__tests__/DrydockBlueprintImplementationTestCase.php', 878 878 'DrydockBlueprintListController' => 'applications/drydock/controller/DrydockBlueprintListController.php', 879 + 'DrydockBlueprintNameNgrams' => 'applications/drydock/storage/DrydockBlueprintNameNgrams.php', 879 880 'DrydockBlueprintPHIDType' => 'applications/drydock/phid/DrydockBlueprintPHIDType.php', 880 881 'DrydockBlueprintQuery' => 'applications/drydock/query/DrydockBlueprintQuery.php', 881 882 'DrydockBlueprintSearchEngine' => 'applications/drydock/query/DrydockBlueprintSearchEngine.php', ··· 4972 4973 'PhabricatorApplicationTransactionInterface', 4973 4974 'PhabricatorPolicyInterface', 4974 4975 'PhabricatorCustomFieldInterface', 4976 + 'PhabricatorNgramsInterface', 4975 4977 ), 4976 4978 'DrydockBlueprintController' => 'DrydockController', 4977 4979 'DrydockBlueprintCoreCustomField' => array( ··· 4987 4989 'DrydockBlueprintImplementation' => 'Phobject', 4988 4990 'DrydockBlueprintImplementationTestCase' => 'PhabricatorTestCase', 4989 4991 'DrydockBlueprintListController' => 'DrydockBlueprintController', 4992 + 'DrydockBlueprintNameNgrams' => 'PhabricatorSearchNgrams', 4990 4993 'DrydockBlueprintPHIDType' => 'PhabricatorPHIDType', 4991 4994 'DrydockBlueprintQuery' => 'DrydockQuery', 4992 4995 'DrydockBlueprintSearchEngine' => 'PhabricatorApplicationSearchEngine',
+3 -9
src/applications/drydock/controller/DrydockBlueprintListController.php
··· 7 7 } 8 8 9 9 public function handleRequest(AphrontRequest $request) { 10 - $querykey = $request->getURIData('queryKey'); 11 - 12 - $request = $this->getRequest(); 13 - $controller = id(new PhabricatorApplicationSearchController()) 14 - ->setQueryKey($querykey) 15 - ->setSearchEngine(new DrydockBlueprintSearchEngine()) 16 - ->setNavigation($this->buildSideNavView()); 17 - 18 - return $this->delegateToController($controller); 10 + return id(new DrydockBlueprintSearchEngine()) 11 + ->setController($this) 12 + ->buildResponse(); 19 13 } 20 14 21 15 protected function buildApplicationCrumbs() {
+4
src/applications/drydock/editor/DrydockBlueprintEditor.php
··· 11 11 return pht('Drydock Blueprints'); 12 12 } 13 13 14 + protected function supportsSearch() { 15 + return true; 16 + } 17 + 14 18 public function getTransactionTypes() { 15 19 $types = parent::getTransactionTypes(); 16 20
+6
src/applications/drydock/query/DrydockBlueprintQuery.php
··· 39 39 return $this; 40 40 } 41 41 42 + public function withNameNgrams($ngrams) { 43 + return $this->withNgramsConstraint( 44 + new DrydockBlueprintNameNgrams(), 45 + $ngrams); 46 + } 47 + 42 48 public function newResultObject() { 43 49 return new DrydockBlueprint(); 44 50 }
+8
src/applications/drydock/query/DrydockBlueprintSearchEngine.php
··· 18 18 protected function buildQueryFromParameters(array $map) { 19 19 $query = $this->newQuery(); 20 20 21 + if ($map['match'] !== null) { 22 + $query->withNameNgrams($map['match']); 23 + } 24 + 21 25 if ($map['isDisabled'] !== null) { 22 26 $query->withDisabled($map['isDisabled']); 23 27 } ··· 27 31 28 32 protected function buildCustomSearchFields() { 29 33 return array( 34 + id(new PhabricatorSearchTextField()) 35 + ->setLabel(pht('Name Contains')) 36 + ->setKey('match') 37 + ->setDescription(pht('Search for blueprints by name substring.')), 30 38 id(new PhabricatorSearchThreeStateField()) 31 39 ->setLabel(pht('Disabled')) 32 40 ->setKey('isDisabled')
+12 -1
src/applications/drydock/storage/DrydockBlueprint.php
··· 8 8 implements 9 9 PhabricatorApplicationTransactionInterface, 10 10 PhabricatorPolicyInterface, 11 - PhabricatorCustomFieldInterface { 11 + PhabricatorCustomFieldInterface, 12 + PhabricatorNgramsInterface { 12 13 13 14 protected $className; 14 15 protected $blueprintName; ··· 342 343 return $this; 343 344 } 344 345 346 + 347 + /* -( PhabricatorNgramInterface )------------------------------------------ */ 348 + 349 + 350 + public function newNgrams() { 351 + return array( 352 + id(new DrydockBlueprintNameNgrams()) 353 + ->setValue($this->getBlueprintName()), 354 + ); 355 + } 345 356 346 357 }
+18
src/applications/drydock/storage/DrydockBlueprintNameNgrams.php
··· 1 + <?php 2 + 3 + final class DrydockBlueprintNameNgrams 4 + extends PhabricatorSearchNgrams { 5 + 6 + public function getNgramKey() { 7 + return 'blueprintname'; 8 + } 9 + 10 + public function getColumnName() { 11 + return 'blueprintName'; 12 + } 13 + 14 + public function getApplicationName() { 15 + return 'drydock'; 16 + } 17 + 18 + }