From cb49acc2ca71f3b2f4cec579ec002a4efe24a5c1 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 12 Apr 2017 15:35:18 -0700 Subject: [PATCH] Update Phabricator to use intermediate tokens from the query compiler Summary: Depends on D17669. Ref T12137. Ref T12003. Ref T2632. Ref T7860. Converts Phabricator to the new parse + compile workflow with intermediate tokens. Also fixes a bug where searches for `cat"` or similar (unmatched quotes) wouldn't produce a nice exception. Test Plan: - Fulltext searched. - Fulltext searched in Conpherence. - Fulltext searched with bad syntax. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12137, T12003, T7860, T2632 Differential Revision: https://secure.phabricator.com/D17670 --- .../conpherence/query/ConpherenceFulltextQuery.php | 6 +++--- .../PhabricatorMySQLFulltextStorageEngine.php | 7 ++++--- .../cluster/search/PhabricatorSearchService.php | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/applications/conpherence/query/ConpherenceFulltextQuery.php b/src/applications/conpherence/query/ConpherenceFulltextQuery.php index 43de7455ae..ba734049f8 100644 --- a/src/applications/conpherence/query/ConpherenceFulltextQuery.php +++ b/src/applications/conpherence/query/ConpherenceFulltextQuery.php @@ -56,9 +56,9 @@ final class ConpherenceFulltextQuery } if (strlen($this->fulltext)) { - $compiled_query = PhabricatorSearchDocument::newQueryCompiler() - ->setQuery($this->fulltext) - ->compileQuery(); + $compiler = PhabricatorSearchDocument::newQueryCompiler(); + $tokens = $compiler->newTokens($this->fulltext); + $compiled_query = $compiler->compileQuery($tokens); $where[] = qsprintf( $conn_r, diff --git a/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php b/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php index 72c49576f0..626c7435c3 100644 --- a/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php +++ b/src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php @@ -398,12 +398,13 @@ final class PhabricatorMySQLFulltextStorageEngine $stemmer = new PhutilSearchStemmer(); $compiler = PhabricatorSearchDocument::newQueryCompiler() - ->setQuery($raw_query) ->setStemmer($stemmer); + $tokens = $compiler->newTokens($raw_query); + $queries = array(); - $queries[] = $compiler->compileLiteralQuery(); - $queries[] = $compiler->compileStemmedQuery(); + $queries[] = $compiler->compileLiteralQuery($tokens); + $queries[] = $compiler->compileStemmedQuery($tokens); return implode(' ', array_filter($queries)); } diff --git a/src/infrastructure/cluster/search/PhabricatorSearchService.php b/src/infrastructure/cluster/search/PhabricatorSearchService.php index a9ceb0e7e5..8e5b296132 100644 --- a/src/infrastructure/cluster/search/PhabricatorSearchService.php +++ b/src/infrastructure/cluster/search/PhabricatorSearchService.php @@ -253,6 +253,10 @@ class PhabricatorSearchService $res = $engine->executeSearch($query); // return immediately if we get results return $res; + } catch (PhutilSearchQueryCompilerSyntaxException $ex) { + // If there's a query compilation error, return it directly to the + // user: they issued a query with bad syntax. + throw $ex; } catch (Exception $ex) { $exceptions[] = $ex; }