golang全文搜索--使用sphinx
不多废话,测试环境 `ubuntu 13.10`
## 安装
sudo apt-get install sphinxsearch
## 配置
nano /etc/sphinxsearch/sphinx.conf
# 数据源配置
source default
{
type = xmlpipe2
xmlpipe_command = /path/xmlpipe2
xmlpipe_fixup_utf8 = 1
}
# 索引配置
index default
{
type = plain
source = default
# 索引文件路径
path = /path/filename
# 不存储文档信息
docinfo = none
#最小索引词长度
min_word_len = 2
charset_type = utf-8
# 指定utf-8的编码表
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
# 简单分词,只支持0和1,如果要搜索中文,请指定为1
ngram_len = 1
# 需要分词的字符,如果要搜索中文,去掉前面的注释
ngram_chars = U+3000..U+2FA1F
}
## xmlpipe2的格式
...
...
...
...
只要配置文件中 xmlpipe_command 字段配置的可执行文件输出为相应的xml流即可,这样几乎适配了所有数据源
## 生成索引
$ indexer default
Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
indexing index 'default'...
WARNING: Attribute count is 0: switching to none docinfo
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 12288 kb
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 47 bytes
total 0.000 sec, 54970 bytes/sec, 4678.36 docs/sec
total 2 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
total 6 writes, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg
## 查询
$ search 55
Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
index 'default': query '55 ': returned 1 matches of 1 total in 0.000 sec
displaying matches:
1. document=233221, weight=1695
words:
1. '55': 1 documents, 1 hits
## 配置searchd
编辑sphinx配置文件,添加:
## 监听地址
searchd
{
# 监听地址(Unix socket)
listen = /var/log/searchd.sock
# 日志文件
log = /var/log/searchd.log
# 查询日志
query_log = /var/log/query.log
# 客户端读取超时时间
read_timeout = 5
# 客户端请求超时时间
client_timeout = 3000
# PID 文件
pid_file = /var/log/searchd.pid
}
## 运行searchd
$ sudo searchd
Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
WARNING: compat_sphinxql_magics=1 is deprecated; please update your application and config
listening on UNIX socket /var/log/searchd.sock
precaching index 'default'
precached 1 indexes in 0.000 sec
验证一下状态
$ searchd --status
Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
searchd status
--------------
uptime: 7
connections: 1
maxed_out: 0
## golang客户端
package main
import (
"github.com/yunge/sphinx"
"log"
)
func main() {
// 链接参数
opts := &sphinx.Options{
Socket: "/var/log/searchd.sock",
Timeout: 5000,
}
// 创建客户端
spClient := &sphinx.Client{Options: opts}
if err := spClient.Error(); err != nil {
log.Fatal(err)
}
// 打开链接
if err := spClient.Open(); err != nil {
log.Fatal(err)
}
// 获取实例信息
status, err := spClient.Status()
if err != nil {
log.Fatal(err)
}
for _, row := range status {
log.Printf("%20s:\t%s\n", row[0], row[1])
}
// 查询
res, err := spClient.Query("33", "default", "Test Query()")
if err != nil {
log.Fatal(err)
}
log.Println(res)
}
输出:
2013/12/05 01:14:55 uptime: 148
2013/12/05 01:14:55 connections: 2
2013/12/05 01:14:55 maxed_out: 0
2013/12/05 01:14:55 command_search: 0
2013/12/05 01:14:55 command_excerpt: 0
2013/12/05 01:14:55 command_update: 0
2013/12/05 01:14:55 command_keywords: 0
2013/12/05 01:14:55 command_persist: 2
2013/12/05 01:14:55 command_status: 2
2013/12/05 01:14:55 command_flushattrs: 0
2013/12/05 01:14:55 agent_connect: 0
2013/12/05 01:14:55 agent_retry: 0
2013/12/05 01:14:55 queries: 0
2013/12/05 01:14:55 dist_queries: 0
2013/12/05 01:14:55 query_wall: 0.000
2013/12/05 01:14:55 query_cpu: OFF
2013/12/05 01:14:55 dist_wall: 0.000
2013/12/05 01:14:55 dist_local: 0.000
2013/12/05 01:14:55 dist_wait: 0.000
2013/12/05 01:14:55 query_reads: OFF
2013/12/05 01:14:55 query_readkb: OFF
2013/12/05 01:14:55 query_readtime: OFF
2013/12/05 01:14:55 avg_query_wall: 0.000
2013/12/05 01:14:55 avg_query_cpu: OFF
2013/12/05 01:14:55 avg_dist_wall: 0.000
2013/12/05 01:14:55 avg_dist_local: 0.000
2013/12/05 01:14:55 avg_dist_wait: 0.000
2013/12/05 01:14:55 avg_query_reads: OFF
2013/12/05 01:14:55 avg_query_readkb: OFF
2013/12/05 01:14:55 avg_query_readtime: OFF
2013/12/05 01:14:55 ] 0}
api参考 http://gowalker.org/github.com/yunge/sphinx
sphinx配置参考 http://www.coreseek.cn/docs/coreseek_4.1-sphinx_2.0.1-beta.html
golang全文搜索--使用sphinx的更多相关文章
- MySQL+Sphinx实现全文搜索
最近在做一个搜索引擎,主要是对图书方面的对象级的搜索,首先来了解下Sphinx吧. 它能够提高你的查询的速度,这个不是一般的快. Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,Pos ...
- mac 下 sphinx + mysql + php 实现全文搜索(xampp)(3)sphinx 的配置项解析
source:数据的来源,数据是从什么地方来的. index:索引,当有数据源之后,从数据源处构建索引.索引实际上就是相当于一个字典检索.有了整本字典内容以后,才会有字典检索. searchd:提供搜 ...
- ubuntu上 安装 基于sphinx 的 coreseek 全文搜索
原生sphinx不支持中文, sphinx-for-chinese匹配中文时也不返回结果 ,真纠结, 最好试了 coreseek,这个能正确返回结果了, 所以记录一下 1 http://www.co ...
- php+中文分词scws+sphinx+mysql打造千万级数据全文搜索
转载自:http://blog.csdn.net/nuli888/article/details/51892776 Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检索引擎.意图 ...
- [转]Sphinx+Mysql+中文分词安装-实现中文全文搜索
From : http://blog.csdn.net/lgm252008/article/details/5373436 1.什么是SphinxSphinx 是一个在GPLv2 下发布的一个全文检索 ...
- window环境下,php+sphinx+coreseek实现简单的中文全文搜索
就以我个人理解来说,sphinx其实是介于客户端和mysql之间的一个索引表,把数据库的没一条记录假设为文档,那么这个索引表其实保存的就是这条记录的关键词及其对应的文档id 1.sphinx的安装 下 ...
- coreseek实战(三):全文搜索在php中应用(使用api接口)
coreseek实战(三):全文搜索在php中应用(使用api接口) 这一篇文章开始学习在php页面中通过api接口,使用coreseek全文搜索. 第一步:综合一下前两篇文章,coreseek实战( ...
- MySQL 全文搜索支持, mysql 5.6.4支持Innodb的全文检索和类memcache的nosql支持
背景:搞个个人博客的全文搜索得用like啥的,现在mysql版本号已经大于5.6.4了也就支持了innodb的全文搜索了,刚查了下目前版本号都到MySQL Community Server 5.6.1 ...
- MySQL 全文搜索支持
MySQL 全文搜索支持 从MySQL 4.0以上 myisam引擎就支持了full text search 全文搜索,在一般的小网站或者blog上可以使用这个特性支持搜索. 那么怎么使用了,简单看看 ...
随机推荐
- [译]GLUT教程 - glutPostRedisplay函数
Lighthouse3d.com >> GLUT Tutorial >> Avoiding the Idle Func >> glutPostRedisplay 直 ...
- HALCON-FUZZY检测用于开关引脚测量
跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...
- opengl的mipmap
压缩纹理是不能调用glGenerateMipmap生成mipmap的. DDS和PVR都不行. 强行调用会产生GL_INVALID_OPERATION的错误. PNG格式试验了glGenerateMi ...
- [UML]UML系列——协作图(通信图)collaboration diagram
系列文章 [UML]UML系列——用例图Use Case [UML]UML系列——用例图中的各种关系(include.extend) [UML]UML系列——类图Class [UML]UML系列——类 ...
- WebApi 服务监控
本文主要介绍在请求WebApi时,监控Action执行的时间,及Action传递的参数值,以及Http请求头信息.采用log4net记录监控日志,通过日志记录的时间方便我们定位哪一个Action执行的 ...
- 安装时出现 Runtiem error (at 62:321) SWbem Locator:服务不存在,或已被标记为删除 该怎么解决?
这是由wmi服务损坏引起的错误 修复WMI服务损坏的批处理程序 将下列代码复制到一个文本文件中,改名为fixwmi.bat,运行即可.需要一段时间,请大家耐心等候. ================= ...
- Android-Universal-Image-Loader三大组件DisplayImageOptions、ImageLoader、ImageLoaderConfiguration详解
一.介绍 Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是提供一个可重复使用的仪器为异步图像加载,缓存和显示.所以,如果你的程序里需要这个功能的话, ...
- C# 通过SerialPort简单调用串口
问题 最近比较经常使用串口进行发送以及传输数据,但是笔者在刚开始接触SerialPort类时,对于Write之后去Read数据的时候,由于设备上面还没有返回数据,读取到的只能是空值.然而,再进行下一次 ...
- MySQL SELECT执行顺序
SELECT语句的完整语法为: () SELECT () DISTINCT <select_list> () FROM <left_table> () <join_typ ...
- Nagios学习笔记四:基于NRPE监控远程Linux主机
1.NRPE简介 Nagios监控远程主机的方法有多种,其方式包括SNMP.NRPE.SSH和NCSA等.这里介绍其通过NRPE监控远程Linux主机的方式. NRPE(Nagios Remote P ...