→WordPressでElasticsearchを利用する設定
編集の要約なし |
|||
(2人の利用者による、間の11版が非表示) | |||
8行目: | 8行目: | ||
*yumリポジトリの確認 | *yumリポジトリの確認 | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash" line start="100"> | ||
vi /etc/yum.repos.d/elasticsearch.repo | vi /etc/yum.repos.d/elasticsearch.repo | ||
[elasticsearch-6.x] | |||
name=Elasticsearch repository for 6.x packages | |||
baseurl=https://artifacts.elastic.co/packages/6.x/yum | |||
gpgcheck=1 | |||
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch | |||
enabled=0 | |||
autorefresh=0 | |||
type=rpm-md | |||
[elasticsearch-5.x] | |||
name=Elasticsearch repository for 5.x packages | |||
baseurl=https://artifacts.elastic.co/packages/5.x/yum | |||
gpgcheck=1 | |||
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch | |||
enabled=0 | |||
autorefresh=0 | |||
type=rpm-md | |||
[elasticsearch-2.x] | [elasticsearch-2.x] | ||
19行目: | 36行目: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
上記は、Elasticsearch 2. | 上記は、Elasticsearch 2.xをインストールする場合の例。現在、MediawikiのExtensionは1.28系が2.x以下をサポートし、1.29系は5.x以上をサポートしている。利用しているExtensionのバージョンとElasticsearchのバージョンを合わせる必要がある。 | ||
*yumを利用したインストール | *yumを利用したインストール | ||
48行目: | 54行目: | ||
*Kuromojiのインストール | *Kuromojiのインストール | ||
Elasticsearch | Elasticsearch 2.xの場合 | ||
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
cd /usr/share/elasticsearch/ | cd /usr/share/elasticsearch/ | ||
bin/plugin install elasticsearch/elasticsearch-analysis-kuromoji | bin/plugin install analysis-kuromoji | ||
</syntaxhighlight> | |||
Elasticsearch 5.xの場合 | |||
<syntaxhighlight lang="bash"> | |||
cd /usr/share/elasticsearch/ | |||
bin/elasticsearch-plugin install analysis-kuromoji | |||
</syntaxhighlight> | </syntaxhighlight> | ||
61行目: | 73行目: | ||
*Indexの作成 | *Indexの作成 | ||
上記Extensionsをインストールする過程で、LocalSettings.phpに以下の設定を追加する。 | 上記Extensionsをインストールする過程で、LocalSettings.phpに以下の設定を追加する。 | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="php"> | ||
Add this to LocalSettings.php: | Add this to LocalSettings.php: | ||
require_once( "$IP/extensions/Elastica/Elastica.php" ); | require_once( "$IP/extensions/Elastica/Elastica.php" ); | ||
69行目: | 81行目: | ||
*設定を保存したら、以下のコマンドを実行し、実行後、$wgDisableSearchUpdate = true;を削除する。 | *設定を保存したら、以下のコマンドを実行し、実行後、$wgDisableSearchUpdate = true;を削除する。 | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="php"> | ||
Now run this script to generate your elasticsearch index: | Now run this script to generate your elasticsearch index: | ||
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php | php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/updateSearchIndexConfig.php | ||
75行目: | 87行目: | ||
*次に、以下のコマンドを実行し、実行後、$wgSearchType = 'CirrusSearch';をLocalSettings.phpへ追加する。 | *次に、以下のコマンドを実行し、実行後、$wgSearchType = 'CirrusSearch';をLocalSettings.phpへ追加する。 | ||
<syntaxhighlight lang=" | <syntaxhighlight lang="php"> | ||
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipLinks --indexOnSkip | php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipLinks --indexOnSkip | ||
php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipParse | php $MW_INSTALL_PATH/extensions/CirrusSearch/maintenance/forceSearchIndex.php --skipParse | ||
81行目: | 93行目: | ||
Once that is complete add this to LocalSettings.php to funnel queries to ElasticSearch: | Once that is complete add this to LocalSettings.php to funnel queries to ElasticSearch: | ||
$wgSearchType = 'CirrusSearch'; | $wgSearchType = 'CirrusSearch'; | ||
</syntaxhighlight> | |||
*Index定期更新のためのcron設定(この例では30分おきに実行される) | |||
<syntaxhighlight lang="bash"> | |||
vi /etc/crontab | |||
0,30 * * * * root /usr/bin/php $mediawikiroot/maintenance/runJobs.php > /var/run/log/runJobs.log 2>&1 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
== WordPressでElasticsearchを利用する設定 == | == WordPressでElasticsearchを利用する設定 == | ||
*推奨プラグイン[https://wordpress.org/plugins/elasticpress/ ElasticPress]を利用する場合は[https://www.arigato.es/tag/elasticsearch/ こちら]を参照。 | |||
*[https://wordpress.org/plugins/fantastic-elasticsearch/ Fantastic Elasticsearch]を利用する場合は以下を参照。 | |||
*analyzer設定の変更 | |||
:src/elasticsearch/Indexer.phpの'analyzer' => 'english'を'kuromoji'へ変更する。この変更はプラグインがバージョンアップされたらリセットされるため注意が必要。 | |||
<syntaxhighlight lang="php" line start="100"> | |||
if($props['type'] == 'string' && $props['index'] == 'analyzed'){ | |||
$lang = Config::apply_filters('string_language', 'english'); | |||
$props = array( | |||
'type' => 'multi_field', | |||
'fields' => array( | |||
$field => $props, | |||
$lang => array_merge($props,array( | |||
'analyzer' => 'kuromoji' /* $lang から'kuromoji'へ変更 */ | |||
) | |||
) | |||
) | |||
); | |||
} | |||
</syntaxhighlight> | |||
Fantastic Elasticsearchが古いバージョンの場合 | |||
<syntaxhighlight lang="php" line start="100"> | |||
if($props['type'] == 'string' && $props['index'] == 'analyzed'){ | |||
$props = array( | |||
'type' => 'multi_field', | |||
'fields' => array( | |||
$field => $props, | |||
'english' => array_merge($props,array( | |||
'analyzer' => 'kuromoji' /* 'english'から'kuromoji'へ変更 */ | |||
) | |||
) | |||
) | |||
); | |||
} | |||
</syntaxhighlight> | |||
== 関連項目 == | |||
[[Tsubopedia:検索の使い方|検索の使い方]] | |||
__NOTOC__ |