xunsearch 解决单字符、无意义字符被分词导致的搜索不准确问题

Xunsearch 配置好启动服务后,我们进行搜索会发现一些单字符如 等被分词,导致搜索结果中出现了与搜索目标不一致但包含这些字符的结果,如此会导致搜索结果不准确。

对于这种问题 Xunsearch 提供了 stopwords.txt 配置文件解决这个问题,只需要将想过滤掉的字符一行一个添加到该文件中,并在启动 xs-searchd 服务时通过 -s 参数 引入 stopwords.txt 文件即可。

sudo /usr/local/xunsearch/bin/xs-searchd -s ./etc/stopwords.txt 

解决 stopwords.txt 不生效问题

在启动 Xunsearch 服务时需要同事启动 xs-indexdxs-searchd 服务, 我们一般使用一键启动脚本 xs-ctl.sh 同时启动这两个服务。

问题就出现在这个脚本,在这个脚本中的 xs-searchd 服务启动命令中没有使用 -s 参数引入 stopwords.txt 文件,因此我们要手动修改 xs-ctl.sh ,添加对 stopwords.txt 文件的引入。

sudo vim /usr/local/xunsearch/bin/xs-ctl.sh

case "$cmd" in
  start|stop|faststop|fastrestart|restart|reload)
  # index 服务
  if test "$server" != "search"; then
    bin/xs-indexd $opt_index $opt_pub -k $cmd
  fi
  # search 服务
  if test "$server" != "index"; then
    # 在 xs-searchd 启动命令中通过 -s 引入 stopwords.txt  文件
    bin/xs-searchd $opt_search $opt_pub -s /usr/local/xunsearch/etc/stopwords.txt -k $cmd
  fi 
  ;;  
*)

保存修改后重启服务即可解决。