@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.

Move Ferret engine "title:..." field definitions to the engine itself

Summary: Ref T12819. Move these out of the core engine into the Ferret engine. In the future different applications can define different functions, like "summary:..." or whatever. This may get more formalization when I possibly do "author:" and such some time down the road.

Test Plan: Searched for "title:...". Searched for "dog:...", got a useful error.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12819

Differential Revision: https://secure.phabricator.com/D18536

+71 -16
+9
src/applications/maniphest/search/ManiphestTaskFerretEngine.php
··· 15 15 return new ManiphestTaskFerretField(); 16 16 } 17 17 18 + protected function getFunctionMap() { 19 + $map = parent::getFunctionMap(); 20 + 21 + $map['body']['aliases'][] = 'desc'; 22 + $map['body']['aliases'][] = 'description'; 23 + 24 + return $map; 25 + } 26 + 18 27 }
+59
src/applications/search/ferret/PhabricatorFerretEngine.php
··· 6 6 abstract public function newDocumentObject(); 7 7 abstract public function newFieldObject(); 8 8 9 + public function getDefaultFunctionKey() { 10 + return 'all'; 11 + } 12 + 13 + public function getFieldForFunction($function) { 14 + $function = phutil_utf8_strtolower($function); 15 + 16 + $map = $this->getFunctionMap(); 17 + if (!isset($map[$function])) { 18 + throw new PhutilSearchQueryCompilerSyntaxException( 19 + pht( 20 + 'Unknown search function "%s". Supported functions are: %s.', 21 + $function, 22 + implode(', ', array_keys($map)))); 23 + } 24 + 25 + return $map[$function]['field']; 26 + } 27 + 28 + public function getAllFunctionFields() { 29 + $map = $this->getFunctionMap(); 30 + 31 + $fields = array(); 32 + foreach ($map as $key => $spec) { 33 + $fields[] = $spec['field']; 34 + } 35 + 36 + return $fields; 37 + } 38 + 39 + protected function getFunctionMap() { 40 + return array( 41 + 'all' => array( 42 + 'field' => PhabricatorSearchDocumentFieldType::FIELD_ALL, 43 + 'aliases' => array( 44 + 'any', 45 + ), 46 + ), 47 + 'title' => array( 48 + 'field' => PhabricatorSearchDocumentFieldType::FIELD_TITLE, 49 + 'aliases' => array(), 50 + ), 51 + 'body' => array( 52 + 'field' => PhabricatorSearchDocumentFieldType::FIELD_BODY, 53 + 'aliases' => array(), 54 + ), 55 + 'core' => array( 56 + 'field' => PhabricatorSearchDocumentFieldType::FIELD_CORE, 57 + 'aliases' => array(), 58 + ), 59 + 'comment' => array( 60 + 'field' => PhabricatorSearchDocumentFieldType::FIELD_COMMENT, 61 + 'aliases' => array( 62 + 'comments', 63 + ), 64 + ), 65 + ); 66 + } 67 + 9 68 public function newStemmer() { 10 69 return new PhutilSearchStemmer(); 11 70 }
+3 -16
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 1402 1402 $this->ferretEngine = $engine; 1403 1403 $this->ferretTokens = $fulltext_tokens; 1404 1404 1405 - 1406 - $function_map = array( 1407 - 'all' => PhabricatorSearchDocumentFieldType::FIELD_ALL, 1408 - 'title' => PhabricatorSearchDocumentFieldType::FIELD_TITLE, 1409 - 'body' => PhabricatorSearchDocumentFieldType::FIELD_BODY, 1410 - 'core' => PhabricatorSearchDocumentFieldType::FIELD_CORE, 1411 - ); 1412 - 1413 - $current_function = 'all'; 1405 + $current_function = $engine->getDefaultFunctionKey(); 1414 1406 $table_map = array(); 1415 1407 $idx = 1; 1416 1408 foreach ($this->ferretTokens as $fulltext_token) { ··· 1421 1413 $function = $current_function; 1422 1414 } 1423 1415 1424 - if (!isset($function_map[$function])) { 1425 - throw new PhutilSearchQueryCompilerSyntaxException( 1426 - pht( 1427 - 'Unknown search function "%s".', 1428 - $function)); 1429 - } 1416 + $raw_field = $engine->getFieldForFunction($function); 1430 1417 1431 1418 if (!isset($table_map[$function])) { 1432 1419 $alias = 'ftfield'.$idx++; 1433 1420 $table_map[$function] = array( 1434 1421 'alias' => $alias, 1435 - 'key' => $function_map[$function], 1422 + 'key' => $raw_field, 1436 1423 ); 1437 1424 } 1438 1425