From e616f166ae9ffaf350468e510fb21d16b36060a5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 13 Aug 2014 15:34:09 -0700 Subject: [PATCH] Provide a setup warning about using the default MySQL stopword file Summary: Fixes T2605. - Add a setup warning about the stopword file. - Provide a simpler stopword file. Test Plan: - Hit setup warning. - Resolved it according to instructions. - Added "various" to a task, then searched for it, found the task. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T2605 Differential Revision: https://secure.phabricator.com/D10258 --- resources/sql/stopwords.txt | 50 ++++++++++++++++++ .../check/PhabricatorSetupCheckMySQL.php | 52 +++++++++++++++++++ ...PhabricatorDefaultSearchEngineSelector.php | 9 +++- 3 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 resources/sql/stopwords.txt diff --git a/resources/sql/stopwords.txt b/resources/sql/stopwords.txt new file mode 100644 index 0000000000..89f5d060f7 --- /dev/null +++ b/resources/sql/stopwords.txt @@ -0,0 +1,50 @@ +the +be +and +of +a +in +to +have +to +it +I +that +for +you +he +with +on +do +say +this +they +at +but +we +his +from +that +not +by +or +as +what +go +their +can +who +get +if +would +all +my +will +as +up +there +so +its +us +in +on diff --git a/src/applications/config/check/PhabricatorSetupCheckMySQL.php b/src/applications/config/check/PhabricatorSetupCheckMySQL.php index 117cc2558e..57fe7af813 100644 --- a/src/applications/config/check/PhabricatorSetupCheckMySQL.php +++ b/src/applications/config/check/PhabricatorSetupCheckMySQL.php @@ -59,6 +59,58 @@ final class PhabricatorSetupCheckMySQL extends PhabricatorSetupCheck { ->setSummary($summary) ->setMessage($message); } + + $stopword_file = queryfx_one($conn_raw, 'SELECT @@ft_stopword_file'); + $stopword_file = $stopword_file['@@ft_stopword_file']; + if ($stopword_file == '(built-in)') { + if (!PhabricatorDefaultSearchEngineSelector::shouldUseElasticSearch()) { + + $root = dirname(phutil_get_library_root('phabricator')); + $stopword_path = $root.'/resources/sql/stopwords.txt'; + $stopword_path = Filesystem::resolvePath($stopword_path); + + $namespace = PhabricatorEnv::getEnvConfig('storage.default-namespace'); + + $summary = pht( + 'MySQL is using a default stopword file, which will prevent '. + 'searching for many common words.'); + + $message = pht( + "Your MySQL instance is using the builtin stopword file for ". + "building search indexes. This can make Phabricator's search ". + "feature less useful.\n\n". + "Stopwords are common words which are not indexed and thus can not ". + "be searched for. The default stopword file has about 500 words, ". + "including various words which you are likely to wish to search ". + "for, such as 'various', 'likely', 'wish', and 'zero'.\n\n". + "To make search more useful, you can use an alternate stopword ". + "file with fewer words. Alternatively, if you aren't concerned ". + "about searching for common words, you can ignore this warning. ". + "If you later plan to configure ElasticSearch, you can also ignore ". + "this warning: this stopword file only affects MySQL fulltext ". + "indexes.\n\n". + "To choose a different stopword file, add this to your %s file ". + "(in the %s section) and then restart %s:\n\n". + "%s\n". + "(You can also use a different file if you prefer. The file ". + "suggested above has about 50 of the most common English words.)\n\n". + "Finally, run this command:\n\n". + "%s", + phutil_tag('tt', array(), 'my.cnf'), + phutil_tag('tt', array(), '[mysqld]'), + phutil_tag('tt', array(), 'mysqld'), + phutil_tag('pre', array(), 'ft_stopword_file='.$stopword_path), + phutil_tag( + 'pre', + array(), + "mysql> REPAIR TABLE {$namespace}_search.search_documentfield;")); + + $this->newIssue('mysql.ft_stopword_file') + ->setName(pht('MySQL is Using Default Stopword File')) + ->setSummary($summary) + ->setMessage($message); + } + } } } diff --git a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php index aa8757ead1..2bd804ed30 100644 --- a/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php +++ b/src/applications/search/selector/PhabricatorDefaultSearchEngineSelector.php @@ -4,11 +4,16 @@ final class PhabricatorDefaultSearchEngineSelector extends PhabricatorSearchEngineSelector { public function newEngine() { - $elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host'); - if ($elastic_host) { + if (self::shouldUseElasticSearch()) { + $elastic_host = PhabricatorEnv::getEnvConfig('search.elastic.host'); $elastic_index = PhabricatorEnv::getEnvConfig('search.elastic.namespace'); return new PhabricatorSearchEngineElastic($elastic_host, $elastic_index); } return new PhabricatorSearchEngineMySQL(); } + + public static function shouldUseElasticSearch() { + return (bool)PhabricatorEnv::getEnvConfig('search.elastic.host'); + } + }