Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15376719
D21108.id50272.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D21108.id50272.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Fri, Mar 14, 5:09 AM (2 w, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7647069
Default Alt Text
D21108.id50272.diff (3 KB)
Attached To
Mode
D21108: Make Ferret query functions sticky only if their values are not quoted
Attached
Detach File
Event Timeline
Log In to Comment