Sphinx Mysql查询问题

时间:2010-10-16 00:21:40

标签: mysql sphinx

source logs
{
    type            = mysql
    sql_host        = localhost
    sql_user        = root
    sql_pass        =
    sql_db            = bot
    sql_port        = 3306
    sql_query_pre    = SET NAMES utf8
    sql_query        = SELECT * FROM logs

    sql_attr_uint   = host

    sql_query_info    = SELECT * FROM logs WHERE id=$id
}

index logs
{
    source          = logs
    path            = D:\Webserver/Sphinx/index/logs
    morphology      = stem_ru, stem_en
    min_word_len    = 1
    charset_type    = utf-8
}

searchd
{
    listen      = 9312
    log         = D:\Webserver/Sphinx/log/searchd.log
    query_log   = D:\Webserver/Sphinx/log/query.log
    pid_file    = D:\Webserver/Sphinx/log/searchd.pid
}

我的数据库:

ID      |     HOST      |      POST     |       URL
1     |       yahoo.com    |    *js3s7Hs56     |   http://yahoo.com     
2     |       google.com    |    7sf6jsg73     |   http://google.com/?asfaa=23

PHP代码Sphinx(搜索)

<?php
    include('sphinxapi.php');

    $cl = new SphinxClient();
    $cl->SetServer( "localhost", 9312 );

    $cl->SetMatchMode( SPH_MATCH_ANY  );
    $result = $cl->Query("google");


    if ( $result === false )
    { 
          echo "Query failed: " . $cl->GetLastError() . ".\n";
    }
    else
    {
        print_r($result);
    }

返回此代码:

2

现在我正在使用sphinx取消所有数据id 2 ??

抱歉英语不好

1 个答案:

答案 0 :(得分:2)

您现在可以获取$ result中返回的ID,并使用它查询您的数据库。

类似的东西:

<?php
    foreach ($result['IDs'] as $ID) {
        $r = mysqli_query('SELECT * FROM `table` WHERE `ID` = ' . $ID);
        # Handle $r
    }

    # Or, more efficiently (depending on how many results you have):

    $IDs = implode(',',array_map('intval',$result['IDs']));
    $r = mysqli_query('SELECT * FROM `table` WHERE `ID` IN (' . $IDs . ')');
    # Handle $r