diff --git a/src/applications/maniphest/search/ManiphestTaskFerretEngine.php b/src/applications/maniphest/search/ManiphestTaskFerretEngine.php --- a/src/applications/maniphest/search/ManiphestTaskFerretEngine.php +++ b/src/applications/maniphest/search/ManiphestTaskFerretEngine.php @@ -15,4 +15,13 @@ return new ManiphestTaskFerretField(); } + protected function getFunctionMap() { + $map = parent::getFunctionMap(); + + $map['body']['aliases'][] = 'desc'; + $map['body']['aliases'][] = 'description'; + + return $map; + } + } diff --git a/src/applications/search/ferret/PhabricatorFerretEngine.php b/src/applications/search/ferret/PhabricatorFerretEngine.php --- a/src/applications/search/ferret/PhabricatorFerretEngine.php +++ b/src/applications/search/ferret/PhabricatorFerretEngine.php @@ -6,6 +6,65 @@ abstract public function newDocumentObject(); abstract public function newFieldObject(); + public function getDefaultFunctionKey() { + return 'all'; + } + + public function getFieldForFunction($function) { + $function = phutil_utf8_strtolower($function); + + $map = $this->getFunctionMap(); + if (!isset($map[$function])) { + throw new PhutilSearchQueryCompilerSyntaxException( + pht( + 'Unknown search function "%s". Supported functions are: %s.', + $function, + implode(', ', array_keys($map)))); + } + + return $map[$function]['field']; + } + + public function getAllFunctionFields() { + $map = $this->getFunctionMap(); + + $fields = array(); + foreach ($map as $key => $spec) { + $fields[] = $spec['field']; + } + + return $fields; + } + + protected function getFunctionMap() { + return array( + 'all' => array( + 'field' => PhabricatorSearchDocumentFieldType::FIELD_ALL, + 'aliases' => array( + 'any', + ), + ), + 'title' => array( + 'field' => PhabricatorSearchDocumentFieldType::FIELD_TITLE, + 'aliases' => array(), + ), + 'body' => array( + 'field' => PhabricatorSearchDocumentFieldType::FIELD_BODY, + 'aliases' => array(), + ), + 'core' => array( + 'field' => PhabricatorSearchDocumentFieldType::FIELD_CORE, + 'aliases' => array(), + ), + 'comment' => array( + 'field' => PhabricatorSearchDocumentFieldType::FIELD_COMMENT, + 'aliases' => array( + 'comments', + ), + ), + ); + } + public function newStemmer() { return new PhutilSearchStemmer(); } diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php --- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php +++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php @@ -1402,15 +1402,7 @@ $this->ferretEngine = $engine; $this->ferretTokens = $fulltext_tokens; - - $function_map = array( - 'all' => PhabricatorSearchDocumentFieldType::FIELD_ALL, - 'title' => PhabricatorSearchDocumentFieldType::FIELD_TITLE, - 'body' => PhabricatorSearchDocumentFieldType::FIELD_BODY, - 'core' => PhabricatorSearchDocumentFieldType::FIELD_CORE, - ); - - $current_function = 'all'; + $current_function = $engine->getDefaultFunctionKey(); $table_map = array(); $idx = 1; foreach ($this->ferretTokens as $fulltext_token) { @@ -1421,18 +1413,13 @@ $function = $current_function; } - if (!isset($function_map[$function])) { - throw new PhutilSearchQueryCompilerSyntaxException( - pht( - 'Unknown search function "%s".', - $function)); - } + $raw_field = $engine->getFieldForFunction($function); if (!isset($table_map[$function])) { $alias = 'ftfield'.$idx++; $table_map[$function] = array( 'alias' => $alias, - 'key' => $function_map[$function], + 'key' => $raw_field, ); }