1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-17 20:32:41 +01:00

Make badges searchable by name

Summary: Closes T10690

Test Plan: Open Badges application, go to Advanced Search, search for a badge by its name and see result.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin

Maniphest Tasks: T10690

Differential Revision: https://secure.phabricator.com/D15656
This commit is contained in:
lkassianik 2016-04-07 12:12:34 -07:00
parent 37b93f4262
commit 1f423c3bd1
8 changed files with 78 additions and 20 deletions

View file

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

View file

@ -0,0 +1,7 @@
CREATE TABLE {$NAMESPACE}_badges.badges_badgename_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

@ -1874,6 +1874,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php', 'PhabricatorBadgesAwardController' => 'applications/badges/controller/PhabricatorBadgesAwardController.php',
'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php', 'PhabricatorBadgesAwardQuery' => 'applications/badges/query/PhabricatorBadgesAwardQuery.php',
'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php', 'PhabricatorBadgesBadge' => 'applications/badges/storage/PhabricatorBadgesBadge.php',
'PhabricatorBadgesBadgeNameNgrams' => 'applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php',
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php', 'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
'PhabricatorBadgesCreateCapability' => 'applications/badges/capability/PhabricatorBadgesCreateCapability.php', 'PhabricatorBadgesCreateCapability' => 'applications/badges/capability/PhabricatorBadgesCreateCapability.php',
@ -6253,7 +6254,9 @@ phutil_register_library_map(array(
'PhabricatorFlaggableInterface', 'PhabricatorFlaggableInterface',
'PhabricatorDestructibleInterface', 'PhabricatorDestructibleInterface',
'PhabricatorConduitResultInterface', 'PhabricatorConduitResultInterface',
'PhabricatorNgramsInterface',
), ),
'PhabricatorBadgesBadgeNameNgrams' => 'PhabricatorSearchNgrams',
'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController', 'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController',
'PhabricatorBadgesController' => 'PhabricatorController', 'PhabricatorBadgesController' => 'PhabricatorController',
'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability', 'PhabricatorBadgesCreateCapability' => 'PhabricatorPolicyCapability',

View file

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

View file

@ -36,6 +36,12 @@ final class PhabricatorBadgesQuery
return $this; return $this;
} }
public function withNameNgrams($ngrams) {
return $this->withNgramsConstraint(
id(new PhabricatorBadgesBadgeNameNgrams()),
$ngrams);
}
public function needRecipients($need_recipients) { public function needRecipients($need_recipients) {
$this->needRecipients = $need_recipients; $this->needRecipients = $need_recipients;
return $this; return $this;
@ -45,6 +51,10 @@ final class PhabricatorBadgesQuery
return $this->loadStandardPage($this->newResultObject()); return $this->loadStandardPage($this->newResultObject());
} }
protected function getPrimaryTableAlias() {
return 'badges';
}
public function newResultObject() { public function newResultObject() {
return new PhabricatorBadgesBadge(); return new PhabricatorBadgesBadge();
} }
@ -73,28 +83,28 @@ final class PhabricatorBadgesQuery
if ($this->ids !== null) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'id IN (%Ld)', 'badges.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids !== null) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'phid IN (%Ls)', 'badges.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->qualities !== null) { if ($this->qualities !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'quality IN (%Ls)', 'badges.quality IN (%Ls)',
$this->qualities); $this->qualities);
} }
if ($this->statuses !== null) { if ($this->statuses !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'status IN (%Ls)', 'badges.status IN (%Ls)',
$this->statuses); $this->statuses);
} }

View file

@ -15,22 +15,12 @@ final class PhabricatorBadgesSearchEngine
return new PhabricatorBadgesQuery(); return new PhabricatorBadgesQuery();
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'statuses',
$this->readListFromRequest($request, 'statuses'));
$saved->setParameter(
'qualities',
$this->readListFromRequest($request, 'qualities'));
return $saved;
}
protected function buildCustomSearchFields() { protected function buildCustomSearchFields() {
return array( return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for badges by name substring.')),
id(new PhabricatorSearchCheckboxesField()) id(new PhabricatorSearchCheckboxesField())
->setKey('qualities') ->setKey('qualities')
->setLabel(pht('Quality')) ->setLabel(pht('Quality'))
@ -55,6 +45,10 @@ final class PhabricatorBadgesSearchEngine
$query->withQualities($map['qualities']); $query->withQualities($map['qualities']);
} }
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
return $query; return $query;
} }

View file

@ -8,7 +8,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
PhabricatorTokenReceiverInterface, PhabricatorTokenReceiverInterface,
PhabricatorFlaggableInterface, PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface, PhabricatorDestructibleInterface,
PhabricatorConduitResultInterface { PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name; protected $name;
protected $flavor; protected $flavor;
@ -59,7 +60,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255', 'name' => 'sort255',
'flavor' => 'text255', 'flavor' => 'text255',
'description' => 'text', 'description' => 'text',
'icon' => 'text255', 'icon' => 'text255',
@ -225,4 +226,14 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
return array(); return array();
} }
/* -( PhabricatorNgramInterface )------------------------------------------ */
public function newNgrams() {
return array(
id(new PhabricatorBadgesBadgeNameNgrams())
->setValue($this->getName()),
);
}
} }

View file

@ -0,0 +1,18 @@
<?php
final class PhabricatorBadgesBadgeNameNgrams
extends PhabricatorSearchNgrams {
public function getNgramKey() {
return 'badgename';
}
public function getColumnName() {
return 'name';
}
public function getApplicationName() {
return 'badges';
}
}