mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Add Room typeahead for Conpherence Search
Summary: Ref T3165. Builds an ngram table for Conpherence Room titles, allowing a tokenizer for searching a subset of rooms. Test Plan: Say `Gabbert` in two different rooms, search all, see two rooms returned. Search specific room, see specific result. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T3165 Differential Revision: https://secure.phabricator.com/D16692
This commit is contained in:
parent
754397c4e7
commit
0244ec3115
8 changed files with 114 additions and 3 deletions
11
resources/sql/autopatches/20161011.conpherence.ngrams.php
Normal file
11
resources/sql/autopatches/20161011.conpherence.ngrams.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
$table = new ConpherenceThread();
|
||||
|
||||
foreach (new LiskMigrationIterator($table) as $thread) {
|
||||
PhabricatorSearchWorker::queueDocumentForIndexing(
|
||||
$thread->getPHID(),
|
||||
array(
|
||||
'force' => true,
|
||||
));
|
||||
}
|
|
@ -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};
|
|
@ -313,6 +313,7 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'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 @@ phutil_register_library_map(array(
|
|||
'PhabricatorApplicationTransactionInterface',
|
||||
'PhabricatorMentionableInterface',
|
||||
'PhabricatorDestructibleInterface',
|
||||
'PhabricatorNgramsInterface',
|
||||
),
|
||||
'ConpherenceThreadDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'ConpherenceThreadIndexEngineExtension' => 'PhabricatorIndexEngineExtension',
|
||||
'ConpherenceThreadListView' => 'AphrontView',
|
||||
'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
|
@ -4822,6 +4826,7 @@ phutil_register_library_map(array(
|
|||
'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'ConpherenceThreadRemarkupRule' => 'PhabricatorObjectRemarkupRule',
|
||||
'ConpherenceThreadSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'ConpherenceThreadTitleNgrams' => 'PhabricatorSearchNgrams',
|
||||
'ConpherenceTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'ConpherenceTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'ConpherenceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
|
|
|
@ -76,6 +76,12 @@ final class ConpherenceThreadQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withTitleNgrams($ngrams) {
|
||||
return $this->withNgramsConstraint(
|
||||
id(new ConpherenceThreadTitleNgrams()),
|
||||
$ngrams);
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$table = new ConpherenceThread();
|
||||
$conn_r = $table->establishConnection('r');
|
||||
|
|
|
@ -22,8 +22,13 @@ final class ConpherenceThreadSearchEngine
|
|||
->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 @@ final class ConpherenceThreadSearchEngine
|
|||
if ($map['fulltext']) {
|
||||
$query->withFulltext($map['fulltext']);
|
||||
}
|
||||
|
||||
if ($map['phids']) {
|
||||
$query->withPHIDs($map['phids']);
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
PhabricatorPolicyInterface,
|
||||
PhabricatorApplicationTransactionInterface,
|
||||
PhabricatorMentionableInterface,
|
||||
PhabricatorDestructibleInterface {
|
||||
PhabricatorDestructibleInterface,
|
||||
PhabricatorNgramsInterface {
|
||||
|
||||
protected $title;
|
||||
protected $topic;
|
||||
|
@ -427,6 +428,16 @@ final class ConpherenceThread extends ConpherenceDAO
|
|||
return $timeline;
|
||||
}
|
||||
|
||||
/* -( PhabricatorNgramInterface )------------------------------------------ */
|
||||
|
||||
|
||||
public function newNgrams() {
|
||||
return array(
|
||||
id(new ConpherenceThreadTitleNgrams())
|
||||
->setValue($this->getTitle()),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* -( PhabricatorDestructibleInterface )----------------------------------- */
|
||||
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue