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

View file

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

View file

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

View file

@ -15,22 +15,12 @@ final class PhabricatorBadgesSearchEngine
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() {
return array(
id(new PhabricatorSearchTextField())
->setLabel(pht('Name Contains'))
->setKey('name')
->setDescription(pht('Search for badges by name substring.')),
id(new PhabricatorSearchCheckboxesField())
->setKey('qualities')
->setLabel(pht('Quality'))
@ -55,6 +45,10 @@ final class PhabricatorBadgesSearchEngine
$query->withQualities($map['qualities']);
}
if ($map['name'] !== null) {
$query->withNameNgrams($map['name']);
}
return $query;
}

View file

@ -8,7 +8,8 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
PhabricatorTokenReceiverInterface,
PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface,
PhabricatorConduitResultInterface {
PhabricatorConduitResultInterface,
PhabricatorNgramsInterface {
protected $name;
protected $flavor;
@ -59,7 +60,7 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255',
'name' => 'sort255',
'flavor' => 'text255',
'description' => 'text',
'icon' => 'text255',
@ -225,4 +226,14 @@ final class PhabricatorBadgesBadge extends PhabricatorBadgesDAO
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';
}
}