mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Add "absent" and "present" field operators to the Ferret query compiler
Summary: Ref T13509. Parse "xyz:-" as "xyz is absent" and "xyz:~" as "xyz is present". These are new operators which the compiler emits separately from "not" and "substring". Test Plan: Added unit tests, ran unit tests. Maniphest Tasks: T13509 Differential Revision: https://secure.phabricator.com/D21107
This commit is contained in:
parent
5c30a60e30
commit
f31b9987ba
2 changed files with 32 additions and 0 deletions
|
@ -12,6 +12,8 @@ final class PhutilSearchQueryCompiler
|
||||||
const OPERATOR_AND = 'and';
|
const OPERATOR_AND = 'and';
|
||||||
const OPERATOR_SUBSTRING = 'sub';
|
const OPERATOR_SUBSTRING = 'sub';
|
||||||
const OPERATOR_EXACT = 'exact';
|
const OPERATOR_EXACT = 'exact';
|
||||||
|
const OPERATOR_ABSENT = 'absent';
|
||||||
|
const OPERATOR_PRESENT = 'present';
|
||||||
|
|
||||||
public function setOperators($operators) {
|
public function setOperators($operators) {
|
||||||
$this->operators = $operators;
|
$this->operators = $operators;
|
||||||
|
@ -300,6 +302,22 @@ final class PhutilSearchQueryCompiler
|
||||||
$require_value = $is_quoted;
|
$require_value = $is_quoted;
|
||||||
|
|
||||||
switch ($operator) {
|
switch ($operator) {
|
||||||
|
case self::OPERATOR_NOT:
|
||||||
|
if ($enable_functions && ($token['function'] !== null)) {
|
||||||
|
$operator = self::OPERATOR_ABSENT;
|
||||||
|
$value = null;
|
||||||
|
} else {
|
||||||
|
$require_value = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case self::OPERATOR_SUBSTRING:
|
||||||
|
if ($enable_functions && ($token['function'] !== null)) {
|
||||||
|
$operator = self::OPERATOR_PRESENT;
|
||||||
|
$value = null;
|
||||||
|
} else {
|
||||||
|
$require_value = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$require_value = true;
|
$require_value = true;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -97,6 +97,8 @@ final class PhutilSearchQueryCompilerTestCase
|
||||||
$op_and = PhutilSearchQueryCompiler::OPERATOR_AND;
|
$op_and = PhutilSearchQueryCompiler::OPERATOR_AND;
|
||||||
$op_sub = PhutilSearchQueryCompiler::OPERATOR_SUBSTRING;
|
$op_sub = PhutilSearchQueryCompiler::OPERATOR_SUBSTRING;
|
||||||
$op_exact = PhutilSearchQueryCompiler::OPERATOR_EXACT;
|
$op_exact = PhutilSearchQueryCompiler::OPERATOR_EXACT;
|
||||||
|
$op_present = PhutilSearchQueryCompiler::OPERATOR_PRESENT;
|
||||||
|
$op_absent = PhutilSearchQueryCompiler::OPERATOR_ABSENT;
|
||||||
|
|
||||||
$mao = "\xE7\x8C\xAB";
|
$mao = "\xE7\x8C\xAB";
|
||||||
|
|
||||||
|
@ -142,6 +144,18 @@ final class PhutilSearchQueryCompilerTestCase
|
||||||
'title:' => false,
|
'title:' => false,
|
||||||
'title:+' => false,
|
'title:+' => false,
|
||||||
'title:+""' => false,
|
'title:+""' => false,
|
||||||
|
'title:""' => false,
|
||||||
|
|
||||||
|
'title:~' => array(
|
||||||
|
array('title', $op_present, null),
|
||||||
|
),
|
||||||
|
|
||||||
|
'title:-' => array(
|
||||||
|
array('title', $op_absent, null),
|
||||||
|
),
|
||||||
|
|
||||||
|
'~' => false,
|
||||||
|
'-' => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertCompileFunctionQueries($function_tests);
|
$this->assertCompileFunctionQueries($function_tests);
|
||||||
|
|
Loading…
Reference in a new issue