mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 14:52:41 +01:00
Support Ferret engine queries in ApplicationSearch via extension instead of hard-code
Summary: Ref T12819. Uses an extension rather than hard-coding support into Maniphest. Test Plan: Saw "Query" field appear in Differential, which also implements the interface and has support. Used field in both applications. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12819 Differential Revision: https://secure.phabricator.com/D18547
This commit is contained in:
parent
395a2ed6d1
commit
551c62b91a
3 changed files with 72 additions and 28 deletions
|
@ -2840,6 +2840,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFerretFulltextEngineExtension' => 'applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php',
|
||||
'PhabricatorFerretInterface' => 'applications/search/ferret/PhabricatorFerretInterface.php',
|
||||
'PhabricatorFerretNgrams' => 'applications/search/ferret/PhabricatorFerretNgrams.php',
|
||||
'PhabricatorFerretSearchEngineExtension' => 'applications/search/engineextension/PhabricatorFerretSearchEngineExtension.php',
|
||||
'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php',
|
||||
'PhabricatorFileAES256StorageFormat' => 'applications/files/format/PhabricatorFileAES256StorageFormat.php',
|
||||
'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php',
|
||||
|
@ -8173,6 +8174,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorFerretField' => 'PhabricatorSearchDAO',
|
||||
'PhabricatorFerretFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension',
|
||||
'PhabricatorFerretNgrams' => 'PhabricatorSearchDAO',
|
||||
'PhabricatorFerretSearchEngineExtension' => 'PhabricatorSearchEngineExtension',
|
||||
'PhabricatorFile' => array(
|
||||
'PhabricatorFileDAO',
|
||||
'PhabricatorApplicationTransactionInterface',
|
||||
|
|
|
@ -49,8 +49,6 @@ final class ManiphestTaskSearchEngine
|
|||
$subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap();
|
||||
$hide_subtypes = (count($subtype_map) == 1);
|
||||
|
||||
$hide_ferret = !PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
|
||||
|
||||
return array(
|
||||
id(new PhabricatorOwnersSearchField())
|
||||
->setLabel(pht('Assigned To'))
|
||||
|
@ -91,10 +89,6 @@ final class ManiphestTaskSearchEngine
|
|||
id(new PhabricatorSearchTextField())
|
||||
->setLabel(pht('Contains Words'))
|
||||
->setKey('fulltext'),
|
||||
id(new PhabricatorSearchTextField())
|
||||
->setLabel(pht('Query (Prototype)'))
|
||||
->setKey('query')
|
||||
->setIsHidden($hide_ferret),
|
||||
id(new PhabricatorSearchThreeStateField())
|
||||
->setLabel(pht('Open Parents'))
|
||||
->setKey('hasParents')
|
||||
|
@ -150,7 +144,6 @@ final class ManiphestTaskSearchEngine
|
|||
'statuses',
|
||||
'priorities',
|
||||
'subtypes',
|
||||
'query',
|
||||
'fulltext',
|
||||
'hasParents',
|
||||
'hasSubtasks',
|
||||
|
@ -231,27 +224,6 @@ final class ManiphestTaskSearchEngine
|
|||
$query->withFullTextSearch($map['fulltext']);
|
||||
}
|
||||
|
||||
if (strlen($map['query'])) {
|
||||
$raw_query = $map['query'];
|
||||
|
||||
$compiler = id(new PhutilSearchQueryCompiler())
|
||||
->setEnableFunctions(true);
|
||||
|
||||
$raw_tokens = $compiler->newTokens($raw_query);
|
||||
|
||||
$fulltext_tokens = array();
|
||||
foreach ($raw_tokens as $raw_token) {
|
||||
$fulltext_token = id(new PhabricatorFulltextToken())
|
||||
->setToken($raw_token);
|
||||
|
||||
$fulltext_tokens[] = $fulltext_token;
|
||||
}
|
||||
|
||||
$query->withFerretConstraint(
|
||||
id(new ManiphestTask())->newFerretEngine(),
|
||||
$fulltext_tokens);
|
||||
}
|
||||
|
||||
if ($map['parentIDs']) {
|
||||
$query->withParentTaskIDs($map['parentIDs']);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorFerretSearchEngineExtension
|
||||
extends PhabricatorSearchEngineExtension {
|
||||
|
||||
const EXTENSIONKEY = 'ferret';
|
||||
|
||||
public function isExtensionEnabled() {
|
||||
return PhabricatorEnv::getEnvConfig('phabricator.show-prototypes');
|
||||
}
|
||||
|
||||
public function getExtensionName() {
|
||||
return pht('Fulltext Search');
|
||||
}
|
||||
|
||||
public function getExtensionOrder() {
|
||||
return 1000;
|
||||
}
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof PhabricatorFerretInterface);
|
||||
}
|
||||
|
||||
public function applyConstraintsToQuery(
|
||||
$object,
|
||||
$query,
|
||||
PhabricatorSavedQuery $saved,
|
||||
array $map) {
|
||||
|
||||
if (!strlen($map['query'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$engine = $object->newFerretEngine();
|
||||
|
||||
$raw_query = $map['query'];
|
||||
|
||||
$compiler = id(new PhutilSearchQueryCompiler())
|
||||
->setEnableFunctions(true);
|
||||
|
||||
$raw_tokens = $compiler->newTokens($raw_query);
|
||||
|
||||
$fulltext_tokens = array();
|
||||
foreach ($raw_tokens as $raw_token) {
|
||||
$fulltext_token = id(new PhabricatorFulltextToken())
|
||||
->setToken($raw_token);
|
||||
|
||||
$fulltext_tokens[] = $fulltext_token;
|
||||
}
|
||||
|
||||
$query->withFerretConstraint($engine, $fulltext_tokens);
|
||||
}
|
||||
|
||||
public function getSearchFields($object) {
|
||||
$fields = array();
|
||||
|
||||
$fields[] = id(new PhabricatorSearchTextField())
|
||||
->setKey('query')
|
||||
->setLabel(pht('Query (Prototype)'))
|
||||
->setDescription(pht('Fulltext search.'));
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
public function getSearchAttachments($object) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue