@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+72 -28
+2
src/__phutil_library_map__.php
··· 2840 2840 'PhabricatorFerretFulltextEngineExtension' => 'applications/search/engineextension/PhabricatorFerretFulltextEngineExtension.php', 2841 2841 'PhabricatorFerretInterface' => 'applications/search/ferret/PhabricatorFerretInterface.php', 2842 2842 'PhabricatorFerretNgrams' => 'applications/search/ferret/PhabricatorFerretNgrams.php', 2843 + 'PhabricatorFerretSearchEngineExtension' => 'applications/search/engineextension/PhabricatorFerretSearchEngineExtension.php', 2843 2844 'PhabricatorFile' => 'applications/files/storage/PhabricatorFile.php', 2844 2845 'PhabricatorFileAES256StorageFormat' => 'applications/files/format/PhabricatorFileAES256StorageFormat.php', 2845 2846 'PhabricatorFileBundleLoader' => 'applications/files/query/PhabricatorFileBundleLoader.php', ··· 8173 8174 'PhabricatorFerretField' => 'PhabricatorSearchDAO', 8174 8175 'PhabricatorFerretFulltextEngineExtension' => 'PhabricatorFulltextEngineExtension', 8175 8176 'PhabricatorFerretNgrams' => 'PhabricatorSearchDAO', 8177 + 'PhabricatorFerretSearchEngineExtension' => 'PhabricatorSearchEngineExtension', 8176 8178 'PhabricatorFile' => array( 8177 8179 'PhabricatorFileDAO', 8178 8180 'PhabricatorApplicationTransactionInterface',
-28
src/applications/maniphest/query/ManiphestTaskSearchEngine.php
··· 49 49 $subtype_map = id(new ManiphestTask())->newEditEngineSubtypeMap(); 50 50 $hide_subtypes = (count($subtype_map) == 1); 51 51 52 - $hide_ferret = !PhabricatorEnv::getEnvConfig('phabricator.show-prototypes'); 53 - 54 52 return array( 55 53 id(new PhabricatorOwnersSearchField()) 56 54 ->setLabel(pht('Assigned To')) ··· 91 89 id(new PhabricatorSearchTextField()) 92 90 ->setLabel(pht('Contains Words')) 93 91 ->setKey('fulltext'), 94 - id(new PhabricatorSearchTextField()) 95 - ->setLabel(pht('Query (Prototype)')) 96 - ->setKey('query') 97 - ->setIsHidden($hide_ferret), 98 92 id(new PhabricatorSearchThreeStateField()) 99 93 ->setLabel(pht('Open Parents')) 100 94 ->setKey('hasParents') ··· 150 144 'statuses', 151 145 'priorities', 152 146 'subtypes', 153 - 'query', 154 147 'fulltext', 155 148 'hasParents', 156 149 'hasSubtasks', ··· 229 222 230 223 if (strlen($map['fulltext'])) { 231 224 $query->withFullTextSearch($map['fulltext']); 232 - } 233 - 234 - if (strlen($map['query'])) { 235 - $raw_query = $map['query']; 236 - 237 - $compiler = id(new PhutilSearchQueryCompiler()) 238 - ->setEnableFunctions(true); 239 - 240 - $raw_tokens = $compiler->newTokens($raw_query); 241 - 242 - $fulltext_tokens = array(); 243 - foreach ($raw_tokens as $raw_token) { 244 - $fulltext_token = id(new PhabricatorFulltextToken()) 245 - ->setToken($raw_token); 246 - 247 - $fulltext_tokens[] = $fulltext_token; 248 - } 249 - 250 - $query->withFerretConstraint( 251 - id(new ManiphestTask())->newFerretEngine(), 252 - $fulltext_tokens); 253 225 } 254 226 255 227 if ($map['parentIDs']) {
+70
src/applications/search/engineextension/PhabricatorFerretSearchEngineExtension.php
··· 1 + <?php 2 + 3 + final class PhabricatorFerretSearchEngineExtension 4 + extends PhabricatorSearchEngineExtension { 5 + 6 + const EXTENSIONKEY = 'ferret'; 7 + 8 + public function isExtensionEnabled() { 9 + return PhabricatorEnv::getEnvConfig('phabricator.show-prototypes'); 10 + } 11 + 12 + public function getExtensionName() { 13 + return pht('Fulltext Search'); 14 + } 15 + 16 + public function getExtensionOrder() { 17 + return 1000; 18 + } 19 + 20 + public function supportsObject($object) { 21 + return ($object instanceof PhabricatorFerretInterface); 22 + } 23 + 24 + public function applyConstraintsToQuery( 25 + $object, 26 + $query, 27 + PhabricatorSavedQuery $saved, 28 + array $map) { 29 + 30 + if (!strlen($map['query'])) { 31 + return; 32 + } 33 + 34 + $engine = $object->newFerretEngine(); 35 + 36 + $raw_query = $map['query']; 37 + 38 + $compiler = id(new PhutilSearchQueryCompiler()) 39 + ->setEnableFunctions(true); 40 + 41 + $raw_tokens = $compiler->newTokens($raw_query); 42 + 43 + $fulltext_tokens = array(); 44 + foreach ($raw_tokens as $raw_token) { 45 + $fulltext_token = id(new PhabricatorFulltextToken()) 46 + ->setToken($raw_token); 47 + 48 + $fulltext_tokens[] = $fulltext_token; 49 + } 50 + 51 + $query->withFerretConstraint($engine, $fulltext_tokens); 52 + } 53 + 54 + public function getSearchFields($object) { 55 + $fields = array(); 56 + 57 + $fields[] = id(new PhabricatorSearchTextField()) 58 + ->setKey('query') 59 + ->setLabel(pht('Query (Prototype)')) 60 + ->setDescription(pht('Fulltext search.')); 61 + 62 + return $fields; 63 + } 64 + 65 + public function getSearchAttachments($object) { 66 + return array(); 67 + } 68 + 69 + 70 + }