分页: 1 / 1

中文全文搜索

发表于 : 2021年3月3日 14:14
davidyin
phpBB的管理后台提供了四种搜索引擎选项:
  • PostgreSQL Fulltext
  • Sphinx Fulltext
  • MySQL Fulltext
  • phpBB Native Fulltext
其中只有 Sphinx Fulltext 对于中文的支持是最好的。

首先要在你的服务器上安装 sphinx 搜索服务。目前这个版本是 Sphinx 2.2.11,可以在 phpBB 3.3.3上正常运行。
简单介绍一下我这里的设置以及环境。
Ubuntu 20.04 LTS
phpBB 3.3.3

在论坛安装正常可以运行的情况下,如下设置。
sudo apt install sphinxsearch

准备数据目录。
mkdir /home/sphinx-phpbbchinese
mkdir /home/sphinx-phpbbchinese/log
sudo chown sphinxsearch:sphinxsearch -R /home/sphinx-phpbbchinese/


设置文件在 /etc/sphinxsearch/ 目录之下。

sudo service sphinxsearch status
查看运行情况。



在phpBB 3.3.x 的后台
搜索设置搜索后端 选择 Sphinx Fulltext

选择后,页面中出现 Sphinx Fulltext 的配置相关的参数。
包括数据文件夹路径,我这里手工修改为 /home/sphinx-phpbbchinese/
主机和端口使用默认的就可以。
内存限制根据你的服务器内存的大小来选择。我这里选择64M
这些修改好之后,点击提交保存。

回到这个配置页面,全选复制 sphinx 配置文件内容。

之后,到 维护搜索索引 ,删除不再使用的搜索引擎的索引,再在 Sphinx Fulltext 创建索引

使用 SSH 登录你的服务器的终端界面。
编辑 /etc/sphinxsearch/sphinx.conf 文件
把上一步所复制的内容,黏贴进去。
记得里面的数据库用户和密码用 mysql 的对应用户替换。
保存退出。


先手工建立完整索引一次。

代码: 全选

sudo indexer --all
在重启 sphinxsearch 服务。

代码: 全选

sudo service sphinxsearch restart

为了让新帖也能被索引进去,在crontab添加下面的命令,可定位每小时运行一次。
下面的这段 ID: beb1050b51dfdab6,在上面的配置文件中可以找到。

代码: 全选

/usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf index_phpbb_beb1050b51dfdab6_main >> /home/sphinx-phpbbchinese/log/indexer.log 2>&1 &

/usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf index_phpbb_beb1050b51dfdab6_delta >> /home/sphinx-phpbbchinese/log/indexer.log 2>&1 &

Re: 中文全文搜索

发表于 : 2021年3月5日 13:41
寂默心流
  亲测好使。不过提醒一下,对于阿里云用户来说 /etc/sphinxsearch/sphinx.conf 最后一段的那个IP不能用阿里云给的公网IP,要用那个公私网IP。另外,防火墙的端口记得打开。

  还有,手动建立索引时会有一个warning,看似不要紧,其实非常影响搜索结果,要在/etc/sphinxsearch/sphinx.conf的index段加上红色那两行!
index index_phpbb_5evtvcsxiqi0djrd_main
{
path = /*****/sphinx/index_phpbb_5evtvcsxiqi0djrd_main
source = source_phpbb_5evtvcsxiqi0djrd_main
docinfo = extern
morphology = none
stopwords =
wordforms = # optional, specify path to wordforms file. See ./docs/sphinx_wordforms.txt for example
exceptions = # optional, specify path to exceptions file. See ./docs/sphinx_exceptions.txt for example
min_word_len = 2
charset_table = U+FF10..U+FF19->0..9, 0..9, U+FF41..U+FF5A->a..z, U+FF21..U+FF3A->a..z, A..Z->a..z, a..z, U+0149, U+017F, U+0138, U+00DF, U+00FF, U+00C0..U+00D6->U+00$ ignore_chars = U+0027, U+002C
min_prefix_len = 3 # Minimum number of characters for wildcard searches by prefix (min 1). Default is 3. If specified, set min_infix_len to 0
min_infix_len = 0 # Minimum number of characters for wildcard searches by infix (min 2). If specified, set min_prefix_len to 0
html_strip = 1
index_exact_words = 0 # Set to 1 to enable exact search operator. Requires wordforms or morphology
blend_chars = U+23, U+24, U+25, U+26, U+40
#####################
ngram_len = 1
ngram_chars = U+3000..U+2FA1F

Re: 中文全文搜索

发表于 : 2021年3月5日 18:05
davidyin
你指的是 listen 的地址?
可以直接用 localhost的。

也许你用的环境同我的不同,我这里没有遇到 warning。

Re: 中文全文搜索

发表于 : 2021年3月5日 20:06
寂默心流
davidyin 写了: 2021年3月5日 18:05 你指的是 listen 的地址?
可以直接用 localhost的。

也许你用的环境同我的不同,我这里没有遇到 warning。
  受教了,已经改成localhost了。我的平台是debian10,跟你的ubuntu差不多。那个warning说的是缓存不足,索引被裁剪了,所以搜索的结果很差,很多首页上的词都搜不到。搞定warning后,彻底大变样,很赞。