3 abstract class FerretSearchFunction
6 abstract public function getFerretFunctionName();
7 abstract public function getFerretFieldKey();
8 abstract public function supportsObject(PhabricatorFerretInterface
$object);
10 final public static function getNormalizedFunctionName($name) {
11 return phutil_utf8_strtolower($name);
14 final public static function validateFerretFunctionName($function_name) {
15 if (!preg_match('/^[a-zA-Z-]+\z/', $function_name)) {
18 'Ferret search engine function name ("%s") is invalid. Function '.
19 'names must be nonempty and may only contain latin letters and '.
25 final public static function validateFerretFunctionFieldKey($field_key) {
26 if (!preg_match('/^[a-z]{4}\z/', $field_key)) {
29 'Ferret search engine field key ("%s") is invalid. Field keys '.
30 'must be exactly four characters long and contain only '.
31 'lowercase latin letters.',
36 final public static function newFerretSearchFunctions() {
37 $extensions = PhabricatorFulltextEngineExtension
::getAllExtensions();
39 $function_map = array();
43 foreach ($extensions as $extension) {
44 $functions = $extension->newFerretSearchFunctions();
46 if (!is_array($functions)) {
49 'Expected fulltext engine extension ("%s") to return a '.
50 'list of functions from "newFerretSearchFunctions()", '.
52 get_class($extension),
53 phutil_describe_type($functions)));
56 foreach ($functions as $idx => $function) {
57 if (!($function instanceof FerretSearchFunction
)) {
60 'Expected fulltext engine extension ("%s") to return a list '.
61 'of "FerretSearchFunction" objects from '.
62 '"newFerretSearchFunctions()", but found something else '.
63 '("%s") at index "%s".',
64 get_class($extension),
65 phutil_describe_type($function),
69 $function_name = $function->getFerretFunctionName();
71 self
::validateFerretFunctionName($function_name);
73 $normal_name = self
::getNormalizedFunctionName(
75 if ($normal_name !== $function_name) {
78 'Ferret function "%s" is specified with a denormalized name. '.
79 'Instead, specify the function using the normalized '.
80 'function name ("%s").',
85 if (isset($function_map[$function_name])) {
86 $other_extension = $function_map[$function_name];
89 'Two different fulltext engine extensions ("%s" and "%s") '.
90 'both define a search function with the same name ("%s"). '.
91 'Each function must have a unique name.',
92 get_class($extension),
93 get_class($other_extension),
96 $function_map[$function_name] = $extension;
98 $field_key = $function->getFerretFieldKey();
100 self
::validateFerretFunctionFieldKey($field_key);
102 if (isset($field_map[$field_key])) {
103 $other_extension = $field_map[$field_key];
106 'Two different fulltext engine extensions ("%s" and "%s") '.
107 'both define a search function with the same key ("%s"). '.
108 'Each function must have a unique key.',
109 get_class($extension),
110 get_class($other_extension),
113 $field_map[$field_key] = $extension;
115 $results[$function_name] = $function;