diff --git a/resources/sql/autopatches/20160406.badges.ngrams.php b/resources/sql/autopatches/20160406.badges.ngrams.php new file mode 100644 index 0000000000..ce8d8896ef --- /dev/null +++ b/resources/sql/autopatches/20160406.badges.ngrams.php @@ -0,0 +1,11 @@ +getPHID(), + array( + 'force' => true, + )); +} diff --git a/resources/sql/autopatches/20160406.badges.ngrams.sql b/resources/sql/autopatches/20160406.badges.ngrams.sql new file mode 100644 index 0000000000..14a03759c9 --- /dev/null +++ b/resources/sql/autopatches/20160406.badges.ngrams.sql @@ -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}; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 9d0150ebee..f6f7cf1865 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/badges/editor/PhabricatorBadgesEditor.php b/src/applications/badges/editor/PhabricatorBadgesEditor.php index c8dc23df3d..e71dd622c8 100644 --- a/src/applications/badges/editor/PhabricatorBadgesEditor.php +++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php @@ -11,6 +11,10 @@ final class PhabricatorBadgesEditor return pht('Badges'); } + protected function supportsSearch() { + return true; + } + public function getTransactionTypes() { $types = parent::getTransactionTypes(); diff --git a/src/applications/badges/query/PhabricatorBadgesQuery.php b/src/applications/badges/query/PhabricatorBadgesQuery.php index c5d8b2dd12..b6277c5f34 100644 --- a/src/applications/badges/query/PhabricatorBadgesQuery.php +++ b/src/applications/badges/query/PhabricatorBadgesQuery.php @@ -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); } diff --git a/src/applications/badges/query/PhabricatorBadgesSearchEngine.php b/src/applications/badges/query/PhabricatorBadgesSearchEngine.php index 025ad3b53f..fc2bf7ef1e 100644 --- a/src/applications/badges/query/PhabricatorBadgesSearchEngine.php +++ b/src/applications/badges/query/PhabricatorBadgesSearchEngine.php @@ -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; } diff --git a/src/applications/badges/storage/PhabricatorBadgesBadge.php b/src/applications/badges/storage/PhabricatorBadgesBadge.php index 95ceb7a9e8..91ed3cf34d 100644 --- a/src/applications/badges/storage/PhabricatorBadgesBadge.php +++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php @@ -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()), + ); + } + } diff --git a/src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php b/src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php new file mode 100644 index 0000000000..c5db47f42d --- /dev/null +++ b/src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php @@ -0,0 +1,18 @@ +