sphinx的安装及配置使用

PHP 专栏收录该内容
11 篇文章 0 订阅

一、下载

http://sphinxsearch.com/downloads/release/


二、安装

解压即可

配置

1.copy根目录下的 sphinx.conf.in到bin目录下的sphinx.conf
2.sphinx.conf的内容为
 

#
# Sphinx configuration file sample
#
# WARNING! While this sample file mentions all available options,
# it contains (very) short helper descriptions only. Please refer to
# doc/sphinx.html for details.
#

#############################################################################
## data source definition
#############################################################################

source database
{
    #数据库信息  
    type        = mysql  
  
    sql_host    = 192.168.10.51    
    sql_user    = tp_test  
    sql_pass    = tp_test123  
    sql_db        = tp_20170508  
    sql_port    = 3306  
    sql_query_pre   = SET NAMES utf8 
}
source base_file_dir:database 
{  
    sql_query  = select d.id, d.`id` as dir_id ,d.`desc`, name, unique_hash, IFNULL(project_name, '') as project_name, member_id, member_id as show_member_id from sg_file_dir d LEFT JOIN sg_file_member m ON d.privilege_hash = m.privilege_hash LEFT JOIN sg_project p ON p.project_sn = d.name  
    sql_attr_uint = dir_id
    sql_attr_uint = show_member_id
    sql_attr_string = unique_hash

#多值属性专用,如果不需要可以去除
    sql_attr_multi = uint member_id from field;select d.id, member_id from sg_file_dir d LEFT JOIN sg_file_member m ON d.privilege_hash = m.privilege_hash group by unique_hash

}

source base_project:database 
{   
    sql_query  = select project_id,project_sn,project_name, project_name as project_title FROM sg_project
      
    sql_attr_uint = project_id
    sql_attr_string = project_title 
}

index file_dir  
{  
    source          = base_file_dir  
    path            = D:/tool/sphinx-2.2.11/data/file_dir
    docinfo         = extern  
    charset_type    = utf-8  
    min_prefix_len  = 0  
    min_infix_len   = 0  
    min_word_len    = 1  
    ngram_len       = 1  
    ngram_chars        = U+3000..U+2FA1F  
  
    charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F  
}

index project  
{  
    source          = base_project  
    path            = D:/tool/sphinx-2.2.11/data/project
    docinfo         = extern  
    charset_type    = utf-8  
    min_prefix_len  = 0  
    min_infix_len   = 0  
    min_word_len    = 1  
    ngram_len       = 1  
    ngram_chars        = U+3000..U+2FA1F  
  
    charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F  
}

indexer  
{  
    mem_limit    = 256M  
}

searchd  
{  
    port            = 3312  
    log             = D:/tool/sphinx-2.2.11/log/searchd.log              #新建的log目录  
    #query_log      = D:/tool/sphinx-2.2.11/log/query.log      #新建的log目录  
    read_timeout    = 5  
    max_children    = 30  
    pid_file        = D:/tool/sphinx-2.2.11/log/searchd.pid        #新建的log目录  
    max_matches     = 1000  
    preopen_indexes    = 0  
    unlink_old    = 1  
    seamless_rotate = 0  
}
# --eof--

 

 

3.生成索引文件
  切换到bin目录下执行:

indexer.exe --all

4.提供检索服务
  searchd.exe

  


php检索sphinx里面的数据
<?php

@header('Content-type:text/html; Charset=utf-8');

$params = $_GET;

require_once('./sphinxapi.php');

$order_column = 'id DESC';//排序规则

//$s = checkSphinx ();

$s = new SphinxClient ();

$s->setServer ( '127.0.0.1', 9312);

$s->setMatchMode(SPH_MATCH_ALL);  //匹配模式

//检索多值(mva)的数据
$s->setFilter('member_id', array(272));

 

$s->SetLimits(($params['page'] - 1) * $params['limit'] , 100000);

$result = $s->query('样品', 'file_dir'); //查找index为file_dir的样品数据

echo '<pre>';

print_r($result);

/*foreach ($result['matches'] as $key => $val) {

    

}*/

 

 

 

 

 

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值