@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.

Make Ferret query functions sticky only if their values are not quoted

Summary:
Ref T13509. Currently, functions are "sticky", but this stickness is in the query execution layer.

Instead:

- move stickiness to the query compiler; and
- make it so that functions are not sticky if their arguments are quoted.

For example:

- `title:x y` previously meant `title:x title:y` (and still does). The "title:" is sticky.
- `title:"x" y` previously meant `title:x title:y`. It now means `title:x all:y`. The "title:" is not sticky because the argument is quoted.

Test Plan: Added unit tests, ran unit tests.

Maniphest Tasks: T13509

Differential Revision: https://secure.phabricator.com/D21108

+38 -5
+21 -1
src/applications/search/compiler/PhutilSearchQueryCompiler.php
··· 262 262 } 263 263 264 264 $results = array(); 265 + $last_function = null; 265 266 foreach ($tokens as $token) { 266 267 $value = implode('', $token['value']); 267 268 $operator_string = implode('', $token['operator']); ··· 339 340 ); 340 341 341 342 if ($enable_functions) { 342 - $result['function'] = $token['function']; 343 + // If a user provides a query like "title:a b c", we interpret all 344 + // of the terms to be title terms: the "title:" function sticks 345 + // until we encounter another function. 346 + 347 + // If a user provides a query like "title:"a"" (with a quoted term), 348 + // the function is not sticky. 349 + 350 + if ($token['function'] !== null) { 351 + $function = $token['function']; 352 + } else { 353 + $function = $last_function; 354 + } 355 + 356 + $result['function'] = $function; 357 + 358 + if ($result['quoted']) { 359 + $last_function = null; 360 + } else { 361 + $last_function = $function; 362 + } 343 363 } 344 364 345 365 $results[] = $result;
+15
src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php
··· 156 156 157 157 '~' => false, 158 158 '-' => false, 159 + 160 + // Functions like "title:" apply to following terms if their term is 161 + // not specified with double quotes. 162 + 'title:x y' => array( 163 + array('title', $op_and, 'x'), 164 + array('title', $op_and, 'y'), 165 + ), 166 + 'title: x y' => array( 167 + array('title', $op_and, 'x'), 168 + array('title', $op_and, 'y'), 169 + ), 170 + 'title:"x" y' => array( 171 + array('title', $op_and, 'x'), 172 + array(null, $op_and, 'y'), 173 + ), 159 174 ); 160 175 161 176 $this->assertCompileFunctionQueries($function_tests);
+2 -4
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
··· 1801 1801 $this->ferretEngine = $engine; 1802 1802 $this->ferretTokens = $fulltext_tokens; 1803 1803 1804 - $current_function = $engine->getDefaultFunctionKey(); 1804 + $default_function = $engine->getDefaultFunctionKey(); 1805 1805 $table_map = array(); 1806 1806 $idx = 1; 1807 1807 foreach ($this->ferretTokens as $fulltext_token) { ··· 1809 1809 $function = $raw_token->getFunction(); 1810 1810 1811 1811 if ($function === null) { 1812 - $function = $current_function; 1812 + $function = $default_function; 1813 1813 } 1814 1814 1815 1815 $raw_field = $engine->getFieldForFunction($function); ··· 1821 1821 'key' => $raw_field, 1822 1822 ); 1823 1823 } 1824 - 1825 - $current_function = $function; 1826 1824 } 1827 1825 1828 1826 // Join the title field separately so we can rank results.