1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

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
This commit is contained in:
epriestley 2017-09-05 10:28:25 -07:00
parent 46abc11114
commit 20aad35e60
3 changed files with 71 additions and 16 deletions

View file

@ -15,4 +15,13 @@ final class ManiphestTaskFerretEngine
return new ManiphestTaskFerretField();
}
protected function getFunctionMap() {
$map = parent::getFunctionMap();
$map['body']['aliases'][] = 'desc';
$map['body']['aliases'][] = 'description';
return $map;
}
}

View file

@ -6,6 +6,65 @@ abstract class PhabricatorFerretEngine extends Phobject {
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();
}

View file

@ -1402,15 +1402,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$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 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$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,
);
}