1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +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:
epriestley 2017-09-06 12:13:50 -07:00
parent 395a2ed6d1
commit 551c62b91a
3 changed files with 72 additions and 28 deletions

View file

@ -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',

View file

@ -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']);
}

View file

@ -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();
}
}