Sphinx(斯芬克司)

2016-08-03  本文已影响64人  日风和

简要描述:

安装步骤

主要配置:

** sphinx.conf **
source mysql
{
    type                    = mysql
    sql_host                = localhost
    sql_user                = root
    sql_pass                = 
    sql_db                  = test
    sql_port                = 3306
    sql_query_pre           = SET NAMES utf8
    sql_query               = SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content FROM documents
                                      #sql_query第一列id需为整数
                                      #title、content作为字符串/文本字段,被全文索引

    sql_attr_uint            = group_id   #从SQL读取到的值必须为整数
    sql_attr_timestamp       = date_added #从SQL读取到的值必须为整数,作为时间属性

    sql_query_info_pre      = SET NAMES utf8   #命令行查询时,设置正确的字符集
    sql_query_info          = SELECT * FROM documents WHERE id=$id #命令行查询时,从数据库读取原始数据信息
}

index mysql
{

    source          = mysql             #对应的source名称
    path            = var/data/mysql #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...

    docinfo           = extern
    mlock             = 0
    morphology        = none
    min_word_len      = 1
    html_strip        = 0

     #charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾
    charset_dictpath = etc/                             #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...
    charset_type        = zh_cn.utf-8
}
 
indexer
{
    mem_limit            = 128M
}


searchd
{
    listen                  =   9312
    read_timeout        = 5
    max_children        = 30
    max_matches            = 1000
    seamless_rotate        = 0
    preopen_indexes        = 0
    unlink_old            = 1
    pid_file = var/log/searchd_mysql.pid  #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
    log = var/log/searchd_mysql.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
    query_log = var/log/query_mysql.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...
    binlog_path =                                #关闭binlog日志

}

配置项说明

参数名 说明
source 定义数据索引源(就是被搜索的数据啦),如果以mysql为索引源,那么source里的信息包含数据库账号、密码、端口、获取数据索引的sql语句等
index 定义如何处理索引源,例如索引文件目录、分词单位、分词配置文件、去除数据的html标签等
indexer 定义indexer服务设置,例如内存使用大小限制、文件索引大小限制
searchd 定义searchd服务设置,用于搜索时的设置,例如服务端口、搜索最大数量限制、搜索超时时间等

接口调用示例

<?php
    $s = new SphinxClient();
    $s->setServer('127.0.0.1', 9312);
    $result = $s->Query('max', 'in_bbs_test');
    echo json_encode($result);
    exit;

返回结果示例

{
    error: "",
    warning: "",
    status: 0,
    fields: [
        "fid",
        "tid",
        "first",
        "author",
        "authorid",
        "subject",
        "dateline",
        "message",
        "useip",
        "port",
        "invisible",
        "anonymous",
        "usesig",
        "htmlon",
        "bbcodeoff",
        "smileyoff",
        "parseurloff",
        "attachment",
        "rate",
        "ratetimes",
        "status",
        "tags",
        "comment",
        "replycredit",
        "position"
    ],
    attrs: [
        
    ],
    matches: {
        
    },
    total: "1000",
    total_found: "4139",
    time: "0.001",
    words: {
        max: {
            docs: "4139",
            hits: "8928"
        }
    }
}

参考资料

上一篇下一篇

猜你喜欢

热点阅读