Page MenuHomePhabricator

D21108.id.diff
No OneTemporary

D21108.id.diff

diff --git a/src/applications/search/compiler/PhutilSearchQueryCompiler.php b/src/applications/search/compiler/PhutilSearchQueryCompiler.php
--- a/src/applications/search/compiler/PhutilSearchQueryCompiler.php
+++ b/src/applications/search/compiler/PhutilSearchQueryCompiler.php
@@ -262,6 +262,7 @@
}
$results = array();
+ $last_function = null;
foreach ($tokens as $token) {
$value = implode('', $token['value']);
$operator_string = implode('', $token['operator']);
@@ -339,7 +340,26 @@
);
if ($enable_functions) {
- $result['function'] = $token['function'];
+ // If a user provides a query like "title:a b c", we interpret all
+ // of the terms to be title terms: the "title:" function sticks
+ // until we encounter another function.
+
+ // If a user provides a query like "title:"a"" (with a quoted term),
+ // the function is not sticky.
+
+ if ($token['function'] !== null) {
+ $function = $token['function'];
+ } else {
+ $function = $last_function;
+ }
+
+ $result['function'] = $function;
+
+ if ($result['quoted']) {
+ $last_function = null;
+ } else {
+ $last_function = $function;
+ }
}
$results[] = $result;
diff --git a/src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php b/src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php
--- a/src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php
+++ b/src/applications/search/compiler/__tests__/PhutilSearchQueryCompilerTestCase.php
@@ -156,6 +156,21 @@
'~' => false,
'-' => false,
+
+ // Functions like "title:" apply to following terms if their term is
+ // not specified with double quotes.
+ 'title:x y' => array(
+ array('title', $op_and, 'x'),
+ array('title', $op_and, 'y'),
+ ),
+ 'title: x y' => array(
+ array('title', $op_and, 'x'),
+ array('title', $op_and, 'y'),
+ ),
+ 'title:"x" y' => array(
+ array('title', $op_and, 'x'),
+ array(null, $op_and, 'y'),
+ ),
);
$this->assertCompileFunctionQueries($function_tests);
diff --git a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
--- a/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
+++ b/src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
@@ -1801,7 +1801,7 @@
$this->ferretEngine = $engine;
$this->ferretTokens = $fulltext_tokens;
- $current_function = $engine->getDefaultFunctionKey();
+ $default_function = $engine->getDefaultFunctionKey();
$table_map = array();
$idx = 1;
foreach ($this->ferretTokens as $fulltext_token) {
@@ -1809,7 +1809,7 @@
$function = $raw_token->getFunction();
if ($function === null) {
- $function = $current_function;
+ $function = $default_function;
}
$raw_field = $engine->getFieldForFunction($function);
@@ -1821,8 +1821,6 @@
'key' => $raw_field,
);
}
-
- $current_function = $function;
}
// Join the title field separately so we can rank results.

File Metadata

Mime Type
text/plain
Expires
Sun, May 12, 9:52 AM (3 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6291080
Default Alt Text
D21108.id.diff (3 KB)

Event Timeline