Skip to main content

Xunsearch检索

简介

Xunsearch 是一个高性能、全功能的全文检索解决方案。 http://www.xunsearch.com/

安装步骤

# 下载安装包
wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2

# 解压安装包
tar -xjf xunsearch-full-latest.tar.bz2

# 执行安装脚本
cd xunsearch-full-1.3.0/
sh setup.sh

# 进入安装目录

# 启动xunsearch服务
bin/xs-ctl.sh restart
bin/xs-ctl.sh -b local start // 监听在本地回环地址 127.0.0.1 上
bin/xs-ctl.sh -b inet start // 监听在所有本地 IP 地址上
bin/xs-ctl.sh -b a.b.c.d start // 监听在指定 IP 上
bin/xs-ctl.sh -b unix start // 分别监听在 tmp/indexd.sock 和 tmp/searchd.sock

# 将启动命令添加到服务器开机自启动
/etc/rc.local

# 数据存储在 $prefix/data 目录中

# 停止和卸载
$prefix/bin/xs-ctl.sh faststop
rm -fr $prefix

索引配置文件

# 配置文件
project.name = content_manage
project.default_charset = utf-8
server.index = 8383
server.search = 8384

[id]
type = id

[username]
index = self
tokenizer = full

[content]
type = body
cutlen = 0
tokenizer = custom

[createtime]
type = string

[description]
type = string
index = mixed

[question]
type = string
index = mixed

遇到的问题

  1. 多个字段如何查询,比如username精准查询,同时模糊查询其他字段
$search->search('subject:上海 人民公园'); // 特别要求 subject 字段包含 "上海"
  1. 在查询数据的时候content字段返回的不完整,这个如何完整展示
# 在配置文件中设置
cutlen = 0
  1. 在搜索的时候,词语可以搜索匹配到,单个汉字不能匹配到,这个如何解决
# 自定义分词器,每个汉字一个分一个词
<?php

class XSTokenizerCustom implements XSTokenizer
{
public function getTokens($value, XSDocument $doc = null)
{

preg_match_all('/./u', $value, $match);
return !empty($match[0]) ? $match[0] : [];

}
}

# 在配置文件中设置
tokenizer = custom