coreseek实时索引全文搜索

工作流程:

  • 安装coreseek(win32版)
  • 建立一个实时索引配置文件
  • 根据配置文件开启searchd服务器
  • 向mysql数据库实时插入数据
  • 启动python客户端访问和搜索

安装coreseek(win32版)

建立实时索引配置文件

  • 解压后,在etc目录下新建一个csft_rt.conf文件
  • 写入如下配置:
#实时索引配置文件
index rt
{
    type                    = rt
    path            = C:\usr\local\coreseek-4.0.1-win32\var\data\rt
    
    #中文分词配置
    charset_dictpath = C:\usr\local\coreseek-4.0.1-win32\etc\                             
    charset_type        = zh_cn.utf-8

    #文档编号字段
    id                                         

    #全文索引字段
    rt_field                  = movie            
    rt_field                  = url              

    #属性字段
    rt_attr_uint            = groupid
    
    #存储内容字段,字符串类型
    rt_attr_string			= date                 
    rt_attr_string          = movie              
    rt_attr_string          = url       		  

    #RT实时索引内存设置
    rt_mem_limit = 1024M
}

#searchd服务定义
searchd
{
    workers             =   threads
    listen              =   9312
    listen              = localhost:9306:mysql41    
    read_timeout        = 5
    max_children        = 30
    max_matches         = 1000
    seamless_rotate     = 0
    preopen_indexes     = 0
    unlink_old          = 1

    pid_file = C:\usr\local\coreseek-4.0.1-win32\var\log\searchd_rt.pid  

    binlog_flush = 2
    
    binlog_max_log_size = 16M
}

根据配置文件启动searchd服务器

  • 回到解压文件根目录,shift+右键,打开cmd
  • 输入bin\searchd   -c   etc\csft_rt.conf
  • 服务器监听127.0.0.19306端口


  • 打开另一个cmd,输入mysql  -h 127.0.0.1  -P  9306  连接
  • 再输入desc  rt ; 查看属性

往数据库插入实时数据:

import MySQLdb

#connect to mysql db
try:
    db = MySQLdb.connect(host="127.0.0.1", user="root", passwd="1234", port=9306)
    cursor = db.cursor()
    print "Connect to db successfully!"
   
except:
    print "Fail to connect to db!"

#insert data to db
for line in open('C:\Users\Administrator\Desktop\ml-100k\u.item'):
    
    (identity,title,date,other,url) = line.split('|')[0:5]
    
    param = (identity,title,url,'1',date)
    
    sql = "insert into rt (id,movie,url,groupid,date) values(%s,%s,%s,%s,%s)"
    
    cursor.execute(sql,param)


db.commit()
db.close


启动客户端连接服务端搜索:

  • 到解压文件的api目录下,执行test.py   words
  • 这里的搜索词words是 : GoldenEye



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值