gpt4 book ai didi

mysql - Sphinx Mysql查询问题

转载 作者:行者123 更新时间:2023-11-29 09:16:36 25 4
gpt4 key购买 nike

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

抱歉英语不好

最佳答案

您现在可以获取 $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

关于mysql - Sphinx Mysql查询问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3947050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com