开发者

Sphinx Mysql query problem

开发者 https://www.devze.com 2023-01-20 08:46 出处:网络
source logs { type开发者_JAVA百科= mysql sql_host= localhost sql_user= root sql_pass= sql_db= bot sql_port= 3306
source logs
{
    type         开发者_JAVA百科   = 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
}

My database:

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

PHP Code Sphinx (search)

<?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);
    }

This code is returned :

2

As now I'm using sphinx to withdraw all data id 2??

Sorry for bad english


You can now take that ID returned in $result and query your database with it.

Something like:

<?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
0

精彩评论

暂无评论...
验证码 换一张
取 消