Page MenuHomePhabricator

D15322.diff
No OneTemporary

D15322.diff

diff --git a/resources/sql/autopatches/20160221.almanac.5.networkn.sql b/resources/sql/autopatches/20160221.almanac.5.networkn.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160221.almanac.5.networkn.sql
@@ -0,0 +1,7 @@
+CREATE TABLE {$NAMESPACE}_almanac.almanac_networkname_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/resources/sql/autopatches/20160221.almanac.6.networki.php b/resources/sql/autopatches/20160221.almanac.6.networki.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20160221.almanac.6.networki.php
@@ -0,0 +1,11 @@
+<?php
+
+$table = new AlmanacNetwork();
+
+foreach (new LiskMigrationIterator($table) as $network) {
+ PhabricatorSearchWorker::queueDocumentForIndexing(
+ $network->getPHID(),
+ array(
+ 'force' => true,
+ ));
+}
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
@@ -66,6 +66,7 @@
'AlmanacNetworkEditController' => 'applications/almanac/controller/AlmanacNetworkEditController.php',
'AlmanacNetworkEditor' => 'applications/almanac/editor/AlmanacNetworkEditor.php',
'AlmanacNetworkListController' => 'applications/almanac/controller/AlmanacNetworkListController.php',
+ 'AlmanacNetworkNameNgrams' => 'applications/almanac/storage/AlmanacNetworkNameNgrams.php',
'AlmanacNetworkPHIDType' => 'applications/almanac/phid/AlmanacNetworkPHIDType.php',
'AlmanacNetworkQuery' => 'applications/almanac/query/AlmanacNetworkQuery.php',
'AlmanacNetworkSearchEngine' => 'applications/almanac/query/AlmanacNetworkSearchEngine.php',
@@ -4051,11 +4052,13 @@
'PhabricatorApplicationTransactionInterface',
'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
+ 'PhabricatorNgramsInterface',
),
'AlmanacNetworkController' => 'AlmanacController',
'AlmanacNetworkEditController' => 'AlmanacNetworkController',
'AlmanacNetworkEditor' => 'PhabricatorApplicationTransactionEditor',
'AlmanacNetworkListController' => 'AlmanacNetworkController',
+ 'AlmanacNetworkNameNgrams' => 'PhabricatorSearchNgrams',
'AlmanacNetworkPHIDType' => 'PhabricatorPHIDType',
'AlmanacNetworkQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'AlmanacNetworkSearchEngine' => 'PhabricatorApplicationSearchEngine',
diff --git a/src/applications/almanac/editor/AlmanacNetworkEditor.php b/src/applications/almanac/editor/AlmanacNetworkEditor.php
--- a/src/applications/almanac/editor/AlmanacNetworkEditor.php
+++ b/src/applications/almanac/editor/AlmanacNetworkEditor.php
@@ -11,6 +11,10 @@
return pht('Almanac Network');
}
+ protected function supportsSearch() {
+ return true;
+ }
+
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
diff --git a/src/applications/almanac/query/AlmanacNetworkQuery.php b/src/applications/almanac/query/AlmanacNetworkQuery.php
--- a/src/applications/almanac/query/AlmanacNetworkQuery.php
+++ b/src/applications/almanac/query/AlmanacNetworkQuery.php
@@ -16,41 +16,42 @@
return $this;
}
- protected function loadPage() {
- $table = new AlmanacNetwork();
- $conn_r = $table->establishConnection('r');
+ public function newResultObject() {
+ return new AlmanacNetwork();
+ }
- $data = queryfx_all(
- $conn_r,
- 'SELECT * FROM %T %Q %Q %Q',
- $table->getTableName(),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
+ public function withNameNgrams($ngrams) {
+ return $this->withNgramsConstraint(
+ new AlmanacNetworkNameNgrams(),
+ $ngrams);
+ }
- return $table->loadAllFromArray($data);
+ protected function loadPage() {
+ return $this->loadStandardPage($this->newResultObject());
}
- protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
- $where = array();
+ protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
+ $where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
- $conn_r,
- 'id IN (%Ld)',
+ $conn,
+ 'network.id IN (%Ld)',
$this->ids);
}
if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
- 'phid IN (%Ls)',
+ $conn,
+ 'network.phid IN (%Ls)',
$this->phids);
}
- $where[] = $this->buildPagingClause($conn_r);
+ return $where;
+ }
- return $this->formatWhereClause($where);
+ protected function getPrimaryTableAlias() {
+ return 'network';
}
public function getQueryApplicationClass() {
diff --git a/src/applications/almanac/query/AlmanacNetworkSearchEngine.php b/src/applications/almanac/query/AlmanacNetworkSearchEngine.php
--- a/src/applications/almanac/query/AlmanacNetworkSearchEngine.php
+++ b/src/applications/almanac/query/AlmanacNetworkSearchEngine.php
@@ -11,22 +11,29 @@
return 'PhabricatorAlmanacApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
+ public function newQuery() {
+ return new AlmanacNetworkQuery();
+ }
- return $saved;
+ protected function buildCustomSearchFields() {
+ return array(
+ id(new PhabricatorSearchTextField())
+ ->setLabel(pht('Name Contains'))
+ ->setKey('match')
+ ->setDescription(pht('Search for devices by name substring.')),
+ );
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new AlmanacNetworkQuery());
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
+
+ if ($map['match'] !== null) {
+ $query->withNameNgrams($map['match']);
+ }
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved_query) {}
-
protected function getURI($path) {
return '/almanac/network/'.$path;
}
@@ -52,12 +59,6 @@
return parent::buildSavedQueryFromBuiltin($query_key);
}
- protected function getRequiredHandlePHIDsForResultList(
- array $networks,
- PhabricatorSavedQuery $query) {
- return array();
- }
-
protected function renderResultList(
array $networks,
PhabricatorSavedQuery $query,
diff --git a/src/applications/almanac/storage/AlmanacNetwork.php b/src/applications/almanac/storage/AlmanacNetwork.php
--- a/src/applications/almanac/storage/AlmanacNetwork.php
+++ b/src/applications/almanac/storage/AlmanacNetwork.php
@@ -5,7 +5,8 @@
implements
PhabricatorApplicationTransactionInterface,
PhabricatorPolicyInterface,
- PhabricatorDestructibleInterface {
+ PhabricatorDestructibleInterface,
+ PhabricatorNgramsInterface {
protected $name;
protected $mailKey;
@@ -114,4 +115,15 @@
$this->delete();
}
+
+/* -( PhabricatorNgramInterface )------------------------------------------ */
+
+
+ public function newNgrams() {
+ return array(
+ id(new AlmanacNetworkNameNgrams())
+ ->setValue($this->getName()),
+ );
+ }
+
}
diff --git a/src/applications/almanac/storage/AlmanacNetworkNameNgrams.php b/src/applications/almanac/storage/AlmanacNetworkNameNgrams.php
new file mode 100644
--- /dev/null
+++ b/src/applications/almanac/storage/AlmanacNetworkNameNgrams.php
@@ -0,0 +1,18 @@
+<?php
+
+final class AlmanacNetworkNameNgrams
+ extends PhabricatorSearchNgrams {
+
+ public function getNgramKey() {
+ return 'networkname';
+ }
+
+ public function getColumnName() {
+ return 'name';
+ }
+
+ public function getApplicationName() {
+ return 'almanac';
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Wed, Nov 13, 4:35 PM (4 d, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6708414
Default Alt Text
D15322.diff (7 KB)

Event Timeline