1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

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
This commit is contained in:
epriestley 2014-08-13 15:34:09 -07:00
parent f1889aa942
commit e616f166ae
3 changed files with 109 additions and 2 deletions

View file

@ -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

View file

@ -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);
}
}
}
}

View file

@ -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');
}
}