Page MenuHomePhabricator

D15656.id37731.diff
No OneTemporary

D15656.id37731.diff

diff --git a/resources/sql/autopatches/20160406.badges.ngrams.php b/resources/sql/autopatches/20160406.badges.ngrams.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160406.badges.ngrams.php
@@ -0,0 +1,11 @@
+<?php
+
+$table = new PhabricatorBadgesBadge();
+
+foreach (new LiskMigrationIterator($table) as $badge) {
+ PhabricatorSearchWorker::queueDocumentForIndexing(
+ $badge->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
--- /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
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1874,6 +1874,7 @@
'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',
@@ -6254,7 +6255,9 @@
'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
--- a/src/applications/badges/editor/PhabricatorBadgesEditor.php
+++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php
@@ -11,6 +11,10 @@
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
--- a/src/applications/badges/query/PhabricatorBadgesQuery.php
+++ b/src/applications/badges/query/PhabricatorBadgesQuery.php
@@ -36,6 +36,12 @@
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 @@
return $this->loadStandardPage($this->newResultObject());
}
+ protected function getPrimaryTableAlias() {
+ return 'badges';
+ }
+
public function newResultObject() {
return new PhabricatorBadgesBadge();
}
@@ -73,28 +83,28 @@
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
--- a/src/applications/badges/query/PhabricatorBadgesSearchEngine.php
+++ b/src/applications/badges/query/PhabricatorBadgesSearchEngine.php
@@ -15,22 +15,12 @@
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 @@
$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
--- a/src/applications/badges/storage/PhabricatorBadgesBadge.php
+++ b/src/applications/badges/storage/PhabricatorBadgesBadge.php
@@ -8,7 +8,8 @@
PhabricatorTokenReceiverInterface,
PhabricatorFlaggableInterface,
PhabricatorDestructibleInterface,
- PhabricatorConduitResultInterface {
+ PhabricatorConduitResultInterface,
+ PhabricatorNgramsInterface {
protected $name;
protected $flavor;
@@ -59,7 +60,7 @@
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 @@
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
--- /dev/null
+++ b/src/applications/badges/storage/PhabricatorBadgesBadgeNameNgrams.php
@@ -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';
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Oct 24, 12:19 AM (2 d, 4 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6745497
Default Alt Text
D15656.id37731.diff (7 KB)

Event Timeline