coreseek note

1.coreseek 安装

http://blog.csdn.net/u011470322/article/details/45331439

http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html#attributes


2.配置

参考http://www.coreseek.cn/docs/coreseek_3.2-sphinx_0.9.9.html#attributes


3.建立索引

/usr/local/coreseek/bin/indexer cn360  --rotate 


4.测试查询中文

<?php
require_once('sphinxapi.php');
// Instantiate the sphinx client
$client = new SphinxClient();
// Set search options
$client->SetServer('localhost', 9312);
$client->SetConnectTimeout(1);
$client->SetArrayResult(true);
// $client->SetMatchMode( SPH_MATCH_ALL  );
$client->SetLimits ( 0, 200 );


// Query the index
$results = $client->Query('惠南工业区','cn360');
// Output the matched results in raw format
print_r($results['matches']);


$ids = array();
foreach ($results['matches'] as $item) {
    $ids[]= $item['id'];
}
var_dump($ids);


$CONF = array('mysql_host'=>'127.0.0.1', 'mysql_username'=>'test', 'mysql_password'=>'test', 'mysql_database'=>'python');
$db = mysql_connect($CONF['mysql_host'],$CONF['mysql_username'],$CONF['mysql_password']) or die("ERROR: unable to connect to database");
var_dump($db);
mysql_select_db($CONF['mysql_database'], $db) or die("ERROR: unable to select database");


$sql = "select * from cn360 where id in( " . implode(",", $ids) . ")";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) > 0) {
    //Fetch Results from Mysql (Store in an accociative array, because they wont be in the right order)
    $rows = array();
    while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
        $rows[$row['id']] = $row;
    }
    print_r($rows);
}


$docs = array();
foreach($ids as $id) {
    if(isset($rows[$id])) {
        $docs[] = $rows[$id];
    }
}


print_r($docs);


result:

Array
(
    [0] => Array
        (
            [id] => 5
            [number] => 059527309155
            [tag] => 谢月明个人
            [address] => 福建 惠安县 惠南工业区
        )


    [1] => Array
        (
            [id] => 36255
            [number] => 07522614783
            [tag] => 惠州市惠城区裕达五金塑料电镀加工厂
            [address] => 广东省 惠州市 惠城区 惠环镇平南工业区47号
        )


    [2] => Array
        (
            [id] => 44990
            [number] => 07522622888
            [tag] => 惠胜五金塑胶制品有限公司
            [address] => 广东省 惠州市 惠城区 平南工业区(陈江车管所旁边)
        )


    [3] => Array
        (
            [id] => 102436
            [number] => 059513328899953
            [tag] => 泉州鸿新工艺有限公司
            [address] => 福建省 泉州市 惠安县 东园镇惠安县东园镇惠南工业区
        )


    [4] => Array
        (
            [id] => 36188
            [number] => 07522602821
            [tag] => 惠州赛达电镀制品有限公司
            [address] => 广东省 惠州市 惠城区 惠环镇平南工业区
        )


    [5] => Array
        (
            [id] => 41243
            [number] => 07522600161
            [tag] => 惠州宏利五金塑胶制品厂有限公司
            [address] => 广东省 惠州市 惠城区 惠环镇平南工业区49号小区
        )


    [6] => Array
        (
            [id] => 49407
            [number] => 075589958311
            [tag] => 华艺惠尔陶艺制品(深圳)有限公司
            [address] => 广东省 广州市 越秀区 布吉坂田五和南和勘工业区一栋三楼
        )


    [7] => Array
        (
            [id] => 142891
            [number] => 057582976506
            [tag] => 上虞市虞南金属拉丝有限公司
            [address] => 浙江省 绍兴市 诸暨市 丰惠镇谢桥工业区3号
        )


    [8] => Array
        (
            [id] => 60476
            [number] => 07522318512
            [tag] => 信全精密五金(惠州)有限公司
            [address] => 广东省 惠州市 惠城区 中心工业区南2号
        )


)





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值