Page MenuHomePhabricator

D16692.id40185.diff
No OneTemporary

D16692.id40185.diff

diff --git a/resources/sql/autopatches/20161011.conpherence.ngrams.php b/resources/sql/autopatches/20161011.conpherence.ngrams.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20161011.conpherence.ngrams.php
@@ -0,0 +1,11 @@
+<?php
+
+$table = new ConpherenceThread();
+
+foreach (new LiskMigrationIterator($table) as $thread) {
+ PhabricatorSearchWorker::queueDocumentForIndexing(
+ $thread->getPHID(),
+ array(
+ 'force' => true,
+ ));
+}
diff --git a/resources/sql/autopatches/20161011.conpherence.ngrams.sql b/resources/sql/autopatches/20161011.conpherence.ngrams.sql
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20161011.conpherence.ngrams.sql
@@ -0,0 +1,7 @@
+CREATE TABLE {$NAMESPACE}_conpherence.conpherence_threadtitle_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
@@ -313,6 +313,7 @@
'ConpherenceSchemaSpec' => 'applications/conpherence/storage/ConpherenceSchemaSpec.php',
'ConpherenceTestCase' => 'applications/conpherence/__tests__/ConpherenceTestCase.php',
'ConpherenceThread' => 'applications/conpherence/storage/ConpherenceThread.php',
+ 'ConpherenceThreadDatasource' => 'applications/conpherence/typeahead/ConpherenceThreadDatasource.php',
'ConpherenceThreadIndexEngineExtension' => 'applications/conpherence/engineextension/ConpherenceThreadIndexEngineExtension.php',
'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php',
'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php',
@@ -320,6 +321,7 @@
'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php',
'ConpherenceThreadRemarkupRule' => 'applications/conpherence/remarkup/ConpherenceThreadRemarkupRule.php',
'ConpherenceThreadSearchEngine' => 'applications/conpherence/query/ConpherenceThreadSearchEngine.php',
+ 'ConpherenceThreadTitleNgrams' => 'applications/conpherence/storage/ConpherenceThreadTitleNgrams.php',
'ConpherenceTransaction' => 'applications/conpherence/storage/ConpherenceTransaction.php',
'ConpherenceTransactionComment' => 'applications/conpherence/storage/ConpherenceTransactionComment.php',
'ConpherenceTransactionQuery' => 'applications/conpherence/query/ConpherenceTransactionQuery.php',
@@ -4814,7 +4816,9 @@
'PhabricatorApplicationTransactionInterface',
'PhabricatorMentionableInterface',
'PhabricatorDestructibleInterface',
+ 'PhabricatorNgramsInterface',
),
+ 'ConpherenceThreadDatasource' => 'PhabricatorTypeaheadDatasource',
'ConpherenceThreadIndexEngineExtension' => 'PhabricatorIndexEngineExtension',
'ConpherenceThreadListView' => 'AphrontView',
'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver',
@@ -4822,6 +4826,7 @@
'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ConpherenceThreadRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'ConpherenceThreadSearchEngine' => 'PhabricatorApplicationSearchEngine',
+ 'ConpherenceThreadTitleNgrams' => 'PhabricatorSearchNgrams',
'ConpherenceTransaction' => 'PhabricatorApplicationTransaction',
'ConpherenceTransactionComment' => 'PhabricatorApplicationTransactionComment',
'ConpherenceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
diff --git a/src/applications/conpherence/query/ConpherenceThreadQuery.php b/src/applications/conpherence/query/ConpherenceThreadQuery.php
--- a/src/applications/conpherence/query/ConpherenceThreadQuery.php
+++ b/src/applications/conpherence/query/ConpherenceThreadQuery.php
@@ -76,6 +76,12 @@
return $this;
}
+ public function withTitleNgrams($ngrams) {
+ return $this->withNgramsConstraint(
+ id(new ConpherenceThreadTitleNgrams()),
+ $ngrams);
+ }
+
protected function loadPage() {
$table = new ConpherenceThread();
$conn_r = $table->establishConnection('r');
diff --git a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
--- a/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
+++ b/src/applications/conpherence/query/ConpherenceThreadSearchEngine.php
@@ -22,8 +22,13 @@
->setLabel(pht('Participants'))
->setKey('participants')
->setAliases(array('participant')),
+ id(new PhabricatorSearchDatasourceField())
+ ->setLabel(pht('Rooms'))
+ ->setKey('phids')
+ ->setDescription(pht('Search by room titles.'))
+ ->setDatasource(id(new ConpherenceThreadDatasource())),
id(new PhabricatorSearchTextField())
- ->setLabel(pht('Contains Words'))
+ ->setLabel(pht('Room Contains Words'))
->setKey('fulltext'),
);
}
@@ -47,7 +52,9 @@
if ($map['fulltext']) {
$query->withFulltext($map['fulltext']);
}
-
+ if ($map['phids']) {
+ $query->withPHIDs($map['phids']);
+ }
return $query;
}
diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php
--- a/src/applications/conpherence/storage/ConpherenceThread.php
+++ b/src/applications/conpherence/storage/ConpherenceThread.php
@@ -5,7 +5,8 @@
PhabricatorPolicyInterface,
PhabricatorApplicationTransactionInterface,
PhabricatorMentionableInterface,
- PhabricatorDestructibleInterface {
+ PhabricatorDestructibleInterface,
+ PhabricatorNgramsInterface {
protected $title;
protected $topic;
@@ -427,6 +428,16 @@
return $timeline;
}
+/* -( PhabricatorNgramInterface )------------------------------------------ */
+
+
+ public function newNgrams() {
+ return array(
+ id(new ConpherenceThreadTitleNgrams())
+ ->setValue($this->getTitle()),
+ );
+ }
+
/* -( PhabricatorDestructibleInterface )----------------------------------- */
diff --git a/src/applications/conpherence/storage/ConpherenceThreadTitleNgrams.php b/src/applications/conpherence/storage/ConpherenceThreadTitleNgrams.php
new file mode 100644
--- /dev/null
+++ b/src/applications/conpherence/storage/ConpherenceThreadTitleNgrams.php
@@ -0,0 +1,17 @@
+<?php
+
+final class ConpherenceThreadTitleNgrams
+ extends PhabricatorSearchNgrams {
+
+ public function getNgramKey() {
+ return 'threadtitle';
+ }
+
+ public function getColumnName() {
+ return 'title';
+ }
+
+ public function getApplicationName() {
+ return 'conpherence';
+ }
+}
diff --git a/src/applications/conpherence/typeahead/ConpherenceThreadDatasource.php b/src/applications/conpherence/typeahead/ConpherenceThreadDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/conpherence/typeahead/ConpherenceThreadDatasource.php
@@ -0,0 +1,47 @@
+<?php
+
+final class ConpherenceThreadDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getBrowseTitle() {
+ return pht('Browse Room');
+ }
+
+ public function getPlaceholderText() {
+ return pht('Type a room title...');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return 'PhabricatorConpherenceApplication';
+ }
+
+ public function loadResults() {
+ $viewer = $this->getViewer();
+ $raw_query = $this->getRawQuery();
+
+ $rooms = id(new ConpherenceThreadQuery())
+ ->setViewer($viewer)
+ ->withTitleNgrams($raw_query)
+ ->needParticipants(true)
+ ->execute();
+
+ $results = array();
+ foreach ($rooms as $room) {
+ if (strlen($room->getTopic())) {
+ $topic = $room->getTopic();
+ } else {
+ $topic = phutil_tag('em', array(), pht('No topic set'));
+ }
+
+ $token = id(new PhabricatorTypeaheadResult())
+ ->setName($room->getTitle())
+ ->setPHID($room->getPHID())
+ ->addAttribute($topic);
+
+ $results[] = $token;
+ }
+
+ return $results;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Jan 30, 8:43 PM (5 h, 47 s)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7075895
Default Alt Text
D16692.id40185.diff (8 KB)

Event Timeline