mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
Interpret search tokens in the for "_..." as substring search
Summary: Ref T13632. Users searching for `__FILE__`, etc., almost certainly mean to perform a substring search. Test Plan: Added tests and made them pass. Searched for various tokens, saw compiler interpretation in UI. Maniphest Tasks: T13632 Differential Revision: https://secure.phabricator.com/D21602
This commit is contained in:
parent
afdef332fb
commit
4cff4dc68b
2 changed files with 32 additions and 5 deletions
|
@ -284,11 +284,24 @@ final class PhutilSearchQueryCompiler
|
|||
$operator = self::OPERATOR_AND;
|
||||
break;
|
||||
case '':
|
||||
// See T12995. If this query term contains Chinese, Japanese or
|
||||
// Korean characters, treat the term as a substring term by default.
|
||||
// These languages do not separate words with spaces, so the term
|
||||
// search mode is normally useless.
|
||||
if ($enable_functions && !$is_quoted && phutil_utf8_is_cjk($value)) {
|
||||
$use_substring = false;
|
||||
|
||||
if ($enable_functions && !$is_quoted) {
|
||||
// See T12995. If this query term contains Chinese, Japanese or
|
||||
// Korean characters, treat the term as a substring term by default.
|
||||
// These languages do not separate words with spaces, so the term
|
||||
// search mode is normally useless.
|
||||
if (phutil_utf8_is_cjk($value)) {
|
||||
$use_substring = true;
|
||||
} else if (phutil_preg_match('/^_/', $value)) {
|
||||
// See T13632. Assume users searching for any term that begins
|
||||
// with an undescore intend to perform substring search if they
|
||||
// don't provide an explicit search function.
|
||||
$use_substring = true;
|
||||
}
|
||||
}
|
||||
|
||||
if ($use_substring) {
|
||||
$operator = self::OPERATOR_SUBSTRING;
|
||||
} else {
|
||||
$operator = self::OPERATOR_AND;
|
||||
|
|
|
@ -205,6 +205,20 @@ final class PhutilSearchQueryCompilerTestCase
|
|||
'xyz',
|
||||
),
|
||||
),
|
||||
|
||||
// See T12995. Interpret CJK tokens as substring queries since these
|
||||
// languages do not use spaces as word separators.
|
||||
"\xE7\x8C\xAB" => array(
|
||||
array(null, $op_sub, "\xE7\x8C\xAB"),
|
||||
),
|
||||
|
||||
// See T13632. Interpret tokens that begin with "_" as substring tokens
|
||||
// if no function is specified.
|
||||
'_x _y_ "_z_"' => array(
|
||||
array(null, $op_sub, '_x'),
|
||||
array(null, $op_sub, '_y_'),
|
||||
array(null, $op_and, '_z_'),
|
||||
),
|
||||
);
|
||||
|
||||
$this->assertCompileFunctionQueries($function_tests);
|
||||
|
|
Loading…
Reference in a new issue