1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 23:02:42 +01:00

Support the Ferret "=" (exact match) operator in the actual query engine

Summary:
Ref PHI778. In D18492, I added support for parsing this operator, but did not actually implement it in the query engine.

Implementation is fairly straightforward. This supports querying for objects by exact title with `title:="exact title"`. This is probably a bad idea, but sometimes maybe useful anyway.

Test Plan: Queried for `title:="xxx"`, found only exact matches.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: ahoffer2

Differential Revision: https://secure.phabricator.com/D19529
This commit is contained in:
epriestley 2018-07-20 15:17:29 -07:00
parent dee453c94d
commit 71d4fa41c9
3 changed files with 25 additions and 0 deletions

View file

@ -60,6 +60,10 @@ final class PhabricatorFulltextToken extends Phobject {
$tip = pht('Substring Search');
$shade = PHUITagView::COLOR_VIOLET;
break;
case PhutilSearchQueryCompiler::OPERATOR_EXACT:
$tip = pht('Exact Search');
$shade = PHUITagView::COLOR_GREEN;
break;
default:
$shade = PHUITagView::COLOR_BLUE;
break;

View file

@ -84,6 +84,7 @@ final class PhabricatorSearchResultView extends AphrontView {
switch ($operator) {
case PhutilSearchQueryCompiler::OPERATOR_SUBSTRING:
case PhutilSearchQueryCompiler::OPERATOR_EXACT:
$patterns[] = '(('.preg_quote($value).'))ui';
break;
case PhutilSearchQueryCompiler::OPERATOR_AND:

View file

@ -1918,6 +1918,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$op_sub = PhutilSearchQueryCompiler::OPERATOR_SUBSTRING;
$op_not = PhutilSearchQueryCompiler::OPERATOR_NOT;
$op_exact = PhutilSearchQueryCompiler::OPERATOR_EXACT;
$where = array();
$current_function = 'all';
@ -1941,6 +1942,25 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$is_substring = false;
}
// If we're doing exact search, just test the raw corpus.
$is_exact = ($raw_token->getOperator() == $op_exact);
if ($is_exact) {
if ($is_not) {
$where[] = qsprintf(
$conn,
'(%T.rawCorpus != %s)',
$table_alias,
$value);
} else {
$where[] = qsprintf(
$conn,
'(%T.rawCorpus = %s)',
$table_alias,
$value);
}
continue;
}
// If we're doing substring search, we just match against the raw corpus
// and we're done.
if ($is_substring) {