Skip to content

Commit f078fd9

Browse files
author
epriestley
committed
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
1 parent 2e19b78 commit f078fd9

File tree

8 files changed

+79
-6
lines changed

8 files changed

+79
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_buildplanname_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};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$table = new HarbormasterBuildPlan();
4+
5+
foreach (new LiskMigrationIterator($table) as $plan) {
6+
PhabricatorSearchWorker::queueDocumentForIndexing(
7+
$plan->getPHID(),
8+
array(
9+
'force' => true,
10+
));
11+
}

src/__phutil_library_map__.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@
10551055
'HarbormasterBuildPlanDefaultViewCapability' => 'applications/harbormaster/capability/HarbormasterBuildPlanDefaultViewCapability.php',
10561056
'HarbormasterBuildPlanEditEngine' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditEngine.php',
10571057
'HarbormasterBuildPlanEditor' => 'applications/harbormaster/editor/HarbormasterBuildPlanEditor.php',
1058+
'HarbormasterBuildPlanNameNgrams' => 'applications/harbormaster/storage/configuration/HarbormasterBuildPlanNameNgrams.php',
10581059
'HarbormasterBuildPlanPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPlanPHIDType.php',
10591060
'HarbormasterBuildPlanQuery' => 'applications/harbormaster/query/HarbormasterBuildPlanQuery.php',
10601061
'HarbormasterBuildPlanSearchEngine' => 'applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php',
@@ -5199,12 +5200,14 @@
51995200
'PhabricatorApplicationTransactionInterface',
52005201
'PhabricatorPolicyInterface',
52015202
'PhabricatorSubscribableInterface',
5203+
'PhabricatorNgramsInterface',
52025204
),
52035205
'HarbormasterBuildPlanDatasource' => 'PhabricatorTypeaheadDatasource',
52045206
'HarbormasterBuildPlanDefaultEditCapability' => 'PhabricatorPolicyCapability',
52055207
'HarbormasterBuildPlanDefaultViewCapability' => 'PhabricatorPolicyCapability',
52065208
'HarbormasterBuildPlanEditEngine' => 'PhabricatorEditEngine',
52075209
'HarbormasterBuildPlanEditor' => 'PhabricatorApplicationTransactionEditor',
5210+
'HarbormasterBuildPlanNameNgrams' => 'PhabricatorSearchNgrams',
52085211
'HarbormasterBuildPlanPHIDType' => 'PhabricatorPHIDType',
52095212
'HarbormasterBuildPlanQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
52105213
'HarbormasterBuildPlanSearchEngine' => 'PhabricatorApplicationSearchEngine',

src/applications/harbormaster/editor/HarbormasterBuildPlanEditor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public function getEditorObjectsDescription() {
1111
return pht('Harbormaster Build Plans');
1212
}
1313

14+
protected function supportsSearch() {
15+
return true;
16+
}
17+
1418
public function getTransactionTypes() {
1519
$types = parent::getTransactionTypes();
1620
$types[] = HarbormasterBuildPlanTransaction::TYPE_NAME;

src/applications/harbormaster/query/HarbormasterBuildPlanQuery.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public function withPlanAutoKeys(array $keys) {
3535
return $this;
3636
}
3737

38+
public function withNameNgrams($ngrams) {
39+
return $this->withNgramsConstraint(
40+
new HarbormasterBuildPlanNameNgrams(),
41+
$ngrams);
42+
}
43+
3844
public function needBuildSteps($need) {
3945
$this->needBuildSteps = $need;
4046
return $this;
@@ -74,41 +80,45 @@ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
7480
if ($this->ids !== null) {
7581
$where[] = qsprintf(
7682
$conn,
77-
'id IN (%Ld)',
83+
'plan.id IN (%Ld)',
7884
$this->ids);
7985
}
8086

8187
if ($this->phids !== null) {
8288
$where[] = qsprintf(
8389
$conn,
84-
'phid IN (%Ls)',
90+
'plan.phid IN (%Ls)',
8591
$this->phids);
8692
}
8793

8894
if ($this->statuses !== null) {
8995
$where[] = qsprintf(
9096
$conn,
91-
'planStatus IN (%Ls)',
97+
'plan.planStatus IN (%Ls)',
9298
$this->statuses);
9399
}
94100

95101
if (strlen($this->datasourceQuery)) {
96102
$where[] = qsprintf(
97103
$conn,
98-
'name LIKE %>',
104+
'plan.name LIKE %>',
99105
$this->datasourceQuery);
100106
}
101107

102108
if ($this->planAutoKeys !== null) {
103109
$where[] = qsprintf(
104110
$conn,
105-
'planAutoKey IN (%Ls)',
111+
'plan.planAutoKey IN (%Ls)',
106112
$this->planAutoKeys);
107113
}
108114

109115
return $where;
110116
}
111117

118+
protected function getPrimaryTableAlias() {
119+
return 'plan';
120+
}
121+
112122
public function getQueryApplicationClass() {
113123
return 'PhabricatorHarbormasterApplication';
114124
}

src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ public function newQuery() {
1717

1818
protected function buildCustomSearchFields() {
1919
return array(
20+
id(new PhabricatorSearchTextField())
21+
->setLabel(pht('Name Contains'))
22+
->setKey('match')
23+
->setDescription(pht('Search for namespaces by name substring.')),
2024
id(new PhabricatorSearchCheckboxesField())
2125
->setLabel(pht('Status'))
2226
->setKey('status')
@@ -32,6 +36,10 @@ protected function buildCustomSearchFields() {
3236
protected function buildQueryFromParameters(array $map) {
3337
$query = $this->newQuery();
3438

39+
if ($map['match'] !== null) {
40+
$query->withNameNgrams($map['match']);
41+
}
42+
3543
if ($map['status']) {
3644
$query->withStatuses($map['status']);
3745
}

src/applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ final class HarbormasterBuildPlan extends HarbormasterDAO
77
implements
88
PhabricatorApplicationTransactionInterface,
99
PhabricatorPolicyInterface,
10-
PhabricatorSubscribableInterface {
10+
PhabricatorSubscribableInterface,
11+
PhabricatorNgramsInterface {
1112

1213
protected $name;
1314
protected $planStatus;
@@ -198,4 +199,15 @@ public function describeAutomaticCapability($capability) {
198199
return $messages;
199200
}
200201

202+
203+
/* -( PhabricatorNgramInterface )------------------------------------------ */
204+
205+
206+
public function newNgrams() {
207+
return array(
208+
id(new HarbormasterBuildPlanNameNgrams())
209+
->setValue($this->getName()),
210+
);
211+
}
212+
201213
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
final class HarbormasterBuildPlanNameNgrams
4+
extends PhabricatorSearchNgrams {
5+
6+
public function getNgramKey() {
7+
return 'buildplanname';
8+
}
9+
10+
public function getColumnName() {
11+
return 'name';
12+
}
13+
14+
public function getApplicationName() {
15+
return 'harbormaster';
16+
}
17+
18+
}

0 commit comments

Comments
 (0)