无法阅读搜索响应

时间:2011-09-15 18:37:48

标签: php search sphinx

我在Sphinx中遇到此错误。

{"status":"failed","status_message":"failed to read searchd response (status=2613, ver=11829, len=774975488, read=66)"}

PHP文件>>我正在暂停tutorial

<?php

require_once('sphinxapi.php');

$sphinxClient = new SphinxClient();
$sphinxClient->SetServer( 'localhost', 3306 );
$sphinxClient->SetConnectTimeout( 1 );

$sphinxClient->SetFieldWeights(array('title' => 70, 'body_text' => 30));

$sphinxClient->SetMatchMode( SPH_MATCH_EXTENDED2 );


$sphinxClient->SetLimits( 0, 20, 1000 );


$sphinxClient->SetRankingMode( SPH_RANK_PROXIMITY_BM25 );

$sphinxClient->SetArrayResult( true );

$searchQuery = "SELECT title FROM `documents` WHERE 1";
$searchResults = $sphinxClient->Query( $searchQuery, '*' );

$jhash = array();

if ( $searchResults === false )
{
    $jhash['status'] = 'failed';
    $jhash['status_message'] = $sphinxClient->GetLastError();
}
else
{
    if ( $sphinxClient->GetLastWarning() )
    {
        $jhash['status'] = 'warning';
        $jhash['status_message'] = $sphinxClient->GetLastWarning();
    }
    else
    {
        $jhash['status'] = 'good';
    }

    $jhash['result_total'] = $searchResults['total'];
    $jhash['result_found'] = $searchResults['total_found'];

    $jhash_matches = array();
    if ( is_array($searchResults["matches"]) )
    {
        $row_ids = array();
        foreach ( $searchResults["matches"] as $docinfo )
        {
            array_push($row_ids, mysql_real_escape_string($docinfo['id']));
        }
    }

    $jhash['matches'] = $jhash_matches;
}

echo json_encode($jhash);

?>

有关问题原因的任何想法吗?

5 个答案:

答案 0 :(得分:4)

将端口号更改为sphinx.conf文件中的任何内容。如果你的sphinx守护进程听到9312改变你的代码如下

$ sphinxClient-&gt; SetServer('localhost',9312);

答案 1 :(得分:3)

我遇到了同样的问题。

在我的配置文件中,我是:

    listen             = 127.0.0.1:9312:mysql41

我必须在另一个端口上添加另一个侦听器

    listen             = 127.0.0.1:9312:mysql41
    listen             = 127.0.0.1:9313

然后在PHP中:

$sphinxsearch->SetServer( 'localhost', 9313 );

不要忘记重启sphinx searchd:

/usr/local/sphinx/bin/searchd --stop

/usr/local/sphinx/bin/searchd -c /usr/local/sphinx/etc/sphinx.conf

答案 2 :(得分:0)

你真的在运行Sphinx守护进程吗?你需要运行这样的东西:

searchd --config sphinx.conf

(并且要停止它,只需添加--stop到结尾)。

答案 3 :(得分:0)

您无法混合使用SphinxQL和API。你搜索查询是完整的SphinxQL查询,应该通过php_mysql查询并通过API查询ypu应该使用更改

$searchQuery = "";
$searchResults = $sphinxClient->Query( $searchQuery, 'documents' );

我也错过了“WHERE 1”的含义;

API和SphinxQL应映射到不同的端口。

答案 4 :(得分:0)

查看错误报告here。从sphinx服务器读取数据时,PHP API中存在问题。