MediaWiki/CirrusSearch

来自百合仙子's Wiki
跳转到导航 跳转到搜索

安装

安装 docker 并运行 elasticsearch.service 服务:

[Unit]
Description=Run ElasticSearch in Docker
After=docker.socket
Requires=docker.socket
Before=mwjobrunner.service php-fpm.service

[Service]
ExecStart=docker run -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" -eES_JAVA_OPTS="-Xms128m -Xmx2g" -v /ldata/data/elasticsearch:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch:7.17.10
Type=exec
Restart=on-failure

[Install]
WantedBy=multi-user.target

mwjobrunner

mwjobrunner.service 服务:

[Unit]
Description=MediaWiki Job runner
After=php-fpm.service postgresql.service

[Service]
ExecStart=/usr/local/bin/mwjobrunner
Type=exec
Nice=10
User=http
OOMScoreAdjust=200
Restart=on-failure

# from php-fpm.service
PrivateTmp=true
ProtectSystem=full
PrivateDevices=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_NETLINK AF_UNIX
RestrictNamespaces=true

[Install]
WantedBy=multi-user.target

mwjobrunner 脚本:

#!/bin/bash

MW_INSTALL_PATH=/usr/share/webapps/mediawiki
RUNJOBS=$MW_INSTALL_PATH/maintenance/runJobs.php
while true; do
  # Job types that need to be run ASAP no matter how many of them are in the queue
  # Those jobs should be very "cheap" to run
  php $RUNJOBS -q --type="enotifNotify"
  # Everything else, limit the number of jobs on each batch
  # The --wait parameter will pause the execution here until new jobs are added,
  # to avoid running the loop without anything to do
  php $RUNJOBS -q --wait --maxjobs=20
  # Wait some seconds to let the CPU do other things, like handling web requests, etc
  sleep 10
done

MediaWiki 插件和配置

安装 mw:Extension:Elasticamw:Extension:CirrusSearch。可选安装 mw:Extension:AdvancedSearch

配置:

wfLoadExtension('Elastica');
wfLoadExtension('CirrusSearch');
wfLoadExtension('AdvancedSearch');
#$wgDisableSearchUpdate = true;
$wgSearchType = 'CirrusSearch';
$wgCirrusSearchUseCompletionSuggester = 'yes';
$wgJobRunRate = 0;

初始化及首次索引,在 /usr/share/webapps/mediawiki/extensions/CirrusSearch/maintenance 下执行

sudo -u http php UpdateSearchIndexConfig.php
sudo -u http php ForceSearchIndex.php --skipLinks --indexOnSkip
sudo -u http php ForceSearchIndex.php --skipParse
sudo -u http php /usr/share/webapps/mediawiki/maintenance/runJobs.php

更多维护命令可以看插件目录中的 README 文件。

支持正则表达式

要给ElasticSearch安装插件,然后调整CirrusSearch配置并重建索引。[1]

对于某些正则表达式,展示的片段可能是页面开头、而非匹配的片段。

不支持零宽断言。

参考资料