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

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
This commit is contained in:
epriestley 2016-03-03 04:17:24 -08:00
parent ba5b32f5bb
commit 01379958fa
9 changed files with 72 additions and 10 deletions

View file

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

View file

@ -0,0 +1,11 @@
<?php
$table = new DrydockBlueprint();
foreach (new LiskMigrationIterator($table) as $blueprint) {
PhabricatorSearchWorker::queueDocumentForIndexing(
$blueprint->getPHID(),
array(
'force' => true,
));
}

View file

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

View file

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

View file

@ -11,6 +11,10 @@ final class DrydockBlueprintEditor
return pht('Drydock Blueprints');
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();

View file

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

View file

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

View file

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

View file

@ -0,0 +1,18 @@
<?php
final class DrydockBlueprintNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'blueprintname';
}
public function getColumnName() {
return 'blueprintName';
}
public function getApplicationName() {
return 'drydock';
}
}