mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-08 22:01:03 +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;
|
$operator = self::OPERATOR_AND;
|
||||||
break;
|
break;
|
||||||
case '':
|
case '':
|
||||||
// See T12995. If this query term contains Chinese, Japanese or
|
$use_substring = false;
|
||||||
// Korean characters, treat the term as a substring term by default.
|
|
||||||
// These languages do not separate words with spaces, so the term
|
if ($enable_functions && !$is_quoted) {
|
||||||
// search mode is normally useless.
|
// See T12995. If this query term contains Chinese, Japanese or
|
||||||
if ($enable_functions && !$is_quoted && phutil_utf8_is_cjk($value)) {
|
// 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;
|
$operator = self::OPERATOR_SUBSTRING;
|
||||||
} else {
|
} else {
|
||||||
$operator = self::OPERATOR_AND;
|
$operator = self::OPERATOR_AND;
|
||||||
|
|
|
@ -205,6 +205,20 @@ final class PhutilSearchQueryCompilerTestCase
|
||||||
'xyz',
|
'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);
|
$this->assertCompileFunctionQueries($function_tests);
|
||||||
|
|
Loading…
Reference in a new issue