安装sonic插件实现flarum全局搜索
首先来到 sonic 官方 github:
https://github.com/valeriansaliou/sonic
注:下面编译sonic和docker运行sonic,二选一,sonic配置文件两者是一样的
编译sonic
编译sonic,由于sonic是rust写的,下面俺们来安装好rust,并配置好编译环境。
1、安装rust
curl https://sh.rustup.rs -sSf | sh
运行选择 1 默认安装,然后:
source $HOME/.cargo/env
检查:
cargo --version
rustc -V
2、配置编译环境和下载sonic源码:
安装依赖
apt install build-essential clang libclang-dev libc6-dev llvm-dev g++ -y
下载源码
git clone https://github.com/valeriansaliou/sonic.git
cd sonic
检查cargo
cargo check
开始编译
cargo build --release
编译好的二进制文件在下面文件夹
./target/release/sonic
复制文件到运行目录
mv sonic /usr/bin
3、编写配置文件
mkdir /etc/sonic
vi /etc/sonic/config.cfg
[server]
log_level = "error"
[channel]
inet = "0.0.0.0:1491"
tcp_timeout = 30
auth_password = "SecretPassword"
[channel.search]
query_limit_default = 10
query_limit_maximum = 100
query_alternates_try = 4
suggest_limit_default = 5
suggest_limit_maximum = 20
[store]
[store.kv]
path = "/var/lib/sonic/store/kv/"
retain_word_objects = 1000
[store.kv.pool]
inactive_after = 1800
[store.kv.database]
flush_after = 900
compress = true
parallelism = 2
max_files = 100
max_compactions = 1
max_flushes = 1
write_buffer = 16384
write_ahead_log = true
[store.fst]
path = "/var/lib/sonic/store/fst/"
[store.fst.pool]
inactive_after = 300
[store.fst.graph]
consolidate_after = 180
max_size = 2048
max_words = 250000
前台运行: sonic -c /etc/sonic/config.cfg
4、编写 systemd 文件后台运行
vi /etc/systemd/system/sonic.service
[Unit]
Description=Sonic Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/sonic -c /etc/sonic/config.cfg
Restart=on-abort
[Install]
WantedBy=multi-user.target
重载systemd
systemctl daemon-reload
启动sonic
systemctl start sonic
开机启动sonic
systemctl enable sonic
docker 运行sonic
docker运行搭配上面 3 的配置文件就可以了,docker和上面编译的sonic,二选一
docker run --restart=always -d -p 1491:1491 -v /etc/sonic/config.cfg:/etc/sonic.cfg -v /etc/sonic/store/:/var/lib/sonic/store/ valeriansaliou/sonic:v1.3.0
安装sonic插件
GitHub:https://github.com/ganuonglachanh/flarum-sonic
cd /var/www/flarum
composer require ganuonglachanh/sonic
去论坛后台开启sonic插件,保持默认配置就行
最后建立索引(安装后只运行这一次就行)
cd /var/www/flarum
php flarum sonic:addtoindex
php flarum cache:clear