Coreseek开源中文检索引擎-Sphinx中文版

来源:互联网 发布:qq辅助软件 编辑:程序博客网 时间:2024/04/28 18:55
实施索引配置:#RT实时索引配置,详情请查看:http://www.coreseek.cn/products-install/rt-indexes/#RT实时索引定义index rtindex{    type                    = rt    path            = var/data/rtindex #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    docinfo            = extern    mlock            = 0    morphology        = none    min_word_len        = 1    html_strip                = 0    #中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/    #charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾    charset_dictpath = etc/                             #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...    charset_type        = zh_cn.utf-8        #RT实时索引字段配置,详情请查看:http://www.coreseek.cn/products-install/rt-indexes/    #字段设置顺序:field, uint, bigint, float, timestamp, string;顺序不可颠倒,否则产生混乱    #使用后,不可更改字段设置,除非删除所有索引文件重新建立,否则产生混乱    #文档编号字段    #id                                               #系统自动处理    #全文索引字段    rt_field                  = title               #全文索引字段    rt_field                  = content         #全文索引字段    #属性字段    rt_attr_uint            = groupid    rt_attr_bigint         = biguid    rt_attr_float           = score    rt_attr_timestamp  = date_added    #存储内容字段    rt_attr_string          = author          #存储author的内容    #已设置全文索引,并需要同时存储内容的字段    rt_attr_string          = title              #同时存储title的内容    rt_attr_string          = content        #同时存储content的内容    #RT实时索引内存设置    rt_mem_limit = 512M}#searchd服务定义searchd{    listen                  =   9312    listen                  = localhost:9306:mysql41    #MySQL 协议支持与SphinxQL,详情请查看:http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html#sphinxql    read_timeout        = 5    max_children        = 30    max_matches            = 1000    seamless_rotate        = 0    preopen_indexes        = 0    unlink_old            = 1    pid_file = var/log/searchd_rtindex.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    log = var/log/searchd_rtindex.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    query_log = var/log/query_rtindex.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    binlog_path = var/log/rtindex/       #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...    binlog_flush = 2    binlog_max_log_size = 16M}
PHP测试程序:<?php// --------------------------------------------------------------------------// File name   : test_coreseek_rtindex.php// Description : coreseek中文全文检索系统实时索引测试程序// Requirement : PHP5 (http://www.php.net)//// Copyright(C), HonestQiao, 2011, All Rights Reserved.//// Author: HonestQiao (honestqiao@gmail.com)//// 最新使用文档,请查看:http://www.coreseek.cn/products/products-install///// --------------------------------------------------------------------------#连接到实时索引,使用MySQL41协议$link = mysql_connect('localhost:9306') or die('connect bad');if (!$link) {    echo mysql_errno() . ": " . mysql_error(). "\n";    exit;}else{    echo "搜索服务:连接成功\n";}#查询id为1的文档$id=1;$query=mysql_query("SELECT * FROM rtindex WHERE id=$id");if(mysql_errno()){    echo mysql_errno() . ": " . mysql_error(). "\n";    exit;}else{    echo "查询数据:查询成功\n";}if(mysql_num_rows($query)){    echo "查询数据:id为 $id 的数据存在\n";    while($row=mysql_fetch_array($query,MYSQL_ASSOC))    {        printf("标题:%s\n",$row['title']);    }}else{    echo "新增数据:插入id为 $id 的数据\n";    $title = '愚人节最佳蛊惑爆料 谷歌300亿美元收购百度';    $content = '据国外媒体报道,谷歌将巨资收购百度......今天看来,“百度一下”已经成为3亿多中国网民的网络生存法则,而直到今天环视全球,真正能像中国一样,拥有自己独立搜索引擎的只有4个国家!......';    $groupid = 1;    $biguid = '12345678901234';    $score = 12.34;    $date_added = time();    $author = '知名编辑';    //主键id,需要自己设置,不会自动生成或者递增(AUTO_INCREMENT)    $content = mysql_escape_string($content);    mysql_query($sql="INSERT INTO rtindex(id,title,content,groupid,biguid,score,date_added,author) VALUES ( $id, '$title', '$content', $groupid,$biguid,$score,$date_added,'$author')");    if(mysql_errno())    {        echo mysql_errno() . ": " . mysql_error(). "\n";        echo $sql;        exit;    }    else    {        echo "新增数据:插入成功\n";    }}echo "\n全文检索:\n";$query=mysql_query("SELECT * FROM rtindex WHERE MATCH('网络搜索')");if(mysql_errno()){    echo mysql_errno() . ": " . mysql_error(). "\n";    exit;}else{    echo "搜索数据:搜索成功\n";}while($row=mysql_fetch_array($query,MYSQL_ASSOC)){    print_r($row);}echo "搜索数据:状态获取\n";$query=mysql_query("SHOW META");if(mysql_errno()){    echo mysql_errno() . ": " . mysql_error(). "\n";    exit;}else{    echo "搜索数据:状态获取成功\n";}while($row=mysql_fetch_array($query,MYSQL_NUM)){    printf("%s\t%s\n",$row[0],$row[1]);}

原创粉丝点击