@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+32 -5
+18 -5
src/applications/search/compiler/PhutilSearchQueryCompiler.php
··· 284 284 $operator = self::OPERATOR_AND; 285 285 break; 286 286 case '': 287 - // See T12995. If this query term contains Chinese, Japanese or 288 - // Korean characters, treat the term as a substring term by default. 289 - // These languages do not separate words with spaces, so the term 290 - // search mode is normally useless. 291 - if ($enable_functions && !$is_quoted && phutil_utf8_is_cjk($value)) { 287 + $use_substring = false; 288 + 289 + if ($enable_functions && !$is_quoted) { 290 + // See T12995. If this query term contains Chinese, Japanese or 291 + // Korean characters, treat the term as a substring term by default. 292 + // These languages do not separate words with spaces, so the term 293 + // search mode is normally useless. 294 + if (phutil_utf8_is_cjk($value)) { 295 + $use_substring = true; 296 + } else if (phutil_preg_match('/^_/', $value)) { 297 + // See T13632. Assume users searching for any term that begins 298 + // with an undescore intend to perform substring search if they 299 + // don't provide an explicit search function. 300 + $use_substring = true; 301 + } 302 + } 303 + 304 + if ($use_substring) { 292 305 $operator = self::OPERATOR_SUBSTRING; 293 306 } else { 294 307 $operator = self::OPERATOR_AND;
+14
src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php
··· 205 205 'xyz', 206 206 ), 207 207 ), 208 + 209 + // See T12995. Interpret CJK tokens as substring queries since these 210 + // languages do not use spaces as word separators. 211 + "\xE7\x8C\xAB" => array( 212 + array(null, $op_sub, "\xE7\x8C\xAB"), 213 + ), 214 + 215 + // See T13632. Interpret tokens that begin with "_" as substring tokens 216 + // if no function is specified. 217 + '_x _y_ "_z_"' => array( 218 + array(null, $op_sub, '_x'), 219 + array(null, $op_sub, '_y_'), 220 + array(null, $op_and, '_z_'), 221 + ), 208 222 ); 209 223 210 224 $this->assertCompileFunctionQueries($function_tests);