@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use PhutilQueryCompiler in Phabricator fulltext search

Summary:
Ref T11741. Fixes T10642. Parse and compile user queries with a consistent ruleset, then submit queries to the backend using whatever ruleset MySQL is configured with.

This means that `ft_boolean_syntax` no longer needs to be configured (we'll just do the right thing in all cases).

This should improve behavior with RDS immediately (T10642), and allow us to improve behavior with InnoDB in the future (T11741).

Test Plan:
- Ran various queries in the UI, saw the expected results.
- Ran bad queries, got useful errors.
- Searched threads in Conpherence.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10642, T11741

Differential Revision: https://secure.phabricator.com/D16939

+33 -40
-38
src/applications/config/check/PhabricatorMySQLSetupCheck.php
··· 248 248 } 249 249 } 250 250 251 - $bool_syntax = $ref->loadRawMySQLConfigValue('ft_boolean_syntax'); 252 - if ($bool_syntax != ' |-><()~*:""&^') { 253 - if ($this->shouldUseMySQLSearchEngine()) { 254 - $summary = pht( 255 - 'MySQL (on host "%s") is configured to search on fulltext indexes '. 256 - 'using "OR" by default. Using "AND" is usually the desired '. 257 - 'behaviour.', 258 - $host_name); 259 - 260 - $message = pht( 261 - "Database host \"%s\" is configured to use the default Boolean ". 262 - "search syntax when using fulltext indexes. This means searching ". 263 - "for 'search words' will yield the query 'search OR words' ". 264 - "instead of the desired 'search AND words'.\n\n". 265 - "This might produce unexpected search results. \n\n". 266 - "You can change this setting to a more sensible default. ". 267 - "Alternatively, you can ignore this warning if ". 268 - "using 'OR' is the desired behaviour. If you later plan ". 269 - "to configure ElasticSearch, you can also ignore this warning: ". 270 - "only MySQL fulltext search is affected.\n\n". 271 - "To change this setting, add this to your %s file ". 272 - "(in the %s section) and then restart %s:\n\n". 273 - "%s\n", 274 - $host_name, 275 - phutil_tag('tt', array(), 'my.cnf'), 276 - phutil_tag('tt', array(), '[mysqld]'), 277 - phutil_tag('tt', array(), 'mysqld'), 278 - phutil_tag('pre', array(), 'ft_boolean_syntax=\' |-><()~*:""&^\'')); 279 - 280 - $this->newIssue('mysql.ft_boolean_syntax') 281 - ->setName(pht('MySQL is Using the Default Boolean Syntax')) 282 - ->setSummary($summary) 283 - ->setMessage($message) 284 - ->setDatabaseRef($ref) 285 - ->addMySQLConfig('ft_boolean_syntax'); 286 - } 287 - } 288 - 289 251 $innodb_pool = $ref->loadRawMySQLConfigValue('innodb_buffer_pool_size'); 290 252 $innodb_bytes = phutil_parse_bytes($innodb_pool); 291 253 $innodb_readable = phutil_format_bytes($innodb_bytes);
+5 -1
src/applications/conpherence/query/ConpherenceFulltextQuery.php
··· 56 56 } 57 57 58 58 if (strlen($this->fulltext)) { 59 + $compiled_query = PhabricatorSearchDocument::newQueryCompiler() 60 + ->setQuery($this->fulltext) 61 + ->compileQuery(); 62 + 59 63 $where[] = qsprintf( 60 64 $conn_r, 61 65 'MATCH(i.corpus) AGAINST (%s IN BOOLEAN MODE)', 62 - $this->fulltext); 66 + $compiled_query); 63 67 } 64 68 65 69 return $this->formatWhereClause($where);
+2
src/applications/search/controller/PhabricatorApplicationSearchController.php
··· 317 317 $exec_errors[] = pht( 318 318 'This query specifies an invalid parameter. Review the '. 319 319 'query parameters and correct errors.'); 320 + } catch (PhutilSearchQueryCompilerSyntaxException $ex) { 321 + $exec_errors[] = $ex->getMessage(); 320 322 } 321 323 322 324 // The engine may have encountered additional errors during rendering;
+10 -1
src/applications/search/fulltextstorage/PhabricatorMySQLFulltextStorageEngine.php
··· 165 165 166 166 $conn_r = $dao_doc->establishConnection('r'); 167 167 168 - $q = $query->getParameter('query'); 168 + $raw_query = $query->getParameter('query'); 169 + $q = $this->compileQuery($raw_query); 169 170 170 171 if (strlen($q)) { 171 172 $join[] = qsprintf( ··· 349 350 } 350 351 351 352 return $sql; 353 + } 354 + 355 + private function compileQuery($raw_query) { 356 + $compiler = PhabricatorSearchDocument::newQueryCompiler(); 357 + 358 + return $compiler 359 + ->setQuery($raw_query) 360 + ->compileQuery(); 352 361 } 353 362 354 363 public function indexExists() {
+16
src/applications/search/storage/document/PhabricatorSearchDocument.php
··· 37 37 return 'phid'; 38 38 } 39 39 40 + public static function newQueryCompiler() { 41 + $table = new self(); 42 + $conn = $table->establishConnection('r'); 43 + 44 + $compiler = new PhutilSearchQueryCompiler(); 45 + 46 + $operators = queryfx_one( 47 + $conn, 48 + 'SELECT @@ft_boolean_syntax AS syntax'); 49 + if ($operators) { 50 + $compiler->setOperators($operators['syntax']); 51 + } 52 + 53 + return $compiler; 54 + } 55 + 40 56 }