使用python测试sphinx(coreseek)做全文索引

 

coreseek是一个基础sphinx的中文索引工具,我今天写一下关于使用python做测试的方式。

1.coreseek安装,连接mysql的配置,先启动sphinx进程,./searched

2.python要连接sphinx肯定是需要第三方库的,

pip install sphinx

/coreseek-3.2.14/csft-3.2.14/api  找到sphinxapi.py,test.py

 

 

3.测试脚本,python test.py  python

cl = SphinxClient()

cl.SetServer ( 'localhost', 9312 )  #主机与端口

cl.SetWeights ( [100, 1] )

cl.SetMatchMode (SPH_MATCH_ANY) #查询的匹配模式,这个自己去了解吧,一般用any

res = cl.Query ( 'python', '*' )  #前一个是关键字,后一个是索引,*代表所有索引

打印print res,看到结果

{'status': 0, 'matches': [{'id': 2, 'weight': 2, 'attrs': {}}, {'id': 4, 'weight': 2, 'attrs': {}}], 'fields': ['title', 'content'], 'time': '0.025', 'total_found': 2, 'warning': '', 'attrs': [], 'words': [{'docs': 2, 'hits': 4, 'word': 'python'}], 'error': '', 'total': 2}

所以res['matches']列表包含了2个字典,遍历一下

for i in res['matches']:

print i['id']

打印出了id,我们取出了id



 

转载于:https://my.oschina.net/afengzxf/blog/3055447

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值