【问题标题】:Sphinx's search.exe returning results correctly but the PHP API is returning nothingSphinx 的 search.exe 正确返回结果,但 PHP API 没有返回任何内容
【发布时间】:2012-10-07 14:19:28
【问题描述】:

我最近为我的 MySQL 数据库安装了 sphinx,并配置了配置文件,并且在运行 search.exe 时得到了正确的结果,但是当我使用 PHP API(以及它的 CodeIgniter 包装器)时。我仍然是 0 零结果。现在我很确定我的 php 代码是正确的,因为它是基本的(获取密钥,运行 mysql 查询,然后返回结果)。什么原因会导致这样的问题?这是 sphinx 配置文件的 searchd 部分,我需要修改什么吗? :

searchd
{
# listen            = 9312
listen          = 9306:mysql41
port            = 3312
log         = C:/sphinx/log/searchd.log
query_log       = C:/sphinx/log/query.log
read_timeout        = 5
max_children        = 30
pid_file        = C:/sphinx/log/searchd.pid
max_matches     = 1000
seamless_rotate     = 1
preopen_indexes     = 1
unlink_old      = 1
workers         = threads # for RT to work
binlog_path     = C:/sphinx/data


}

这是我的 search.php sphinx 查询:

        $search_string=$this->input->post('q');
        $this->load->library('Sphinxclient');
        $this->sphinxclient->setMatchMode(SPH_MATCH_ANY);
        $this->sphinxclient->SetArrayResult(TRUE);
        $users_ids=$this->sphinxclient->Query('users_info',$search_string);

现在我不确定 API 或 sphinx 是如何找到 mysql 目录并连接到它的,但我正在阅读 sphinx 文档,在基本 api 函数部分,它说函数 SetServer 的默认值为“localhost ”和端口“9312”。这可能是问题,因为在我的配置文件中我有一个不同的端口并且我已经注释掉了 9312 监听?

这是我对 users_info 源和索引的定义(尽管我怀疑这是问题,因为 search.exe 能够获得结果)。

source users_info
{
type                            = mysql

sql_host                        = localhost
sql_user                        = admin
sql_pass                        = admin
sql_db                          = users
sql_sock                        =  /var/run/mysqld/mysqld.sock
sql_port                        = 3306                  


sql_query                       = \
        SELECT id, fullname,username FROM users_info;



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

和索引:

index users_info
{
source          = users_info
path            = C:/sphinx/data/users_info
docinfo         = extern
charset_type        = utf-8
}

另外,还有一件事,在 API 中,我翻转了 API 中 Query 函数中的参数,我已经修复了这个问题,但这并没有解决问题。

有什么想法吗?

【问题讨论】:

  • 您是否运行过索引器?另外,运行查询后是否有任何错误?您可以通过运行 $this->sphinxclient->getLastError() 并回显结果来找到它。
  • 问题原来是,在我的表单输入字段中,我没有指定方法,所以它没有得到搜索查询输入。现在一切正常。只是一个nooby错误。非常感谢

标签: php api sphinx config


【解决方案1】:

它表示函数 SetServer 的默认值为“localhost”,端口为“9312”。这可能是问题,因为在我的配置文件中我有一个不同的端口并且我已经注释掉了 9312 监听?

这肯定会导致问题。您需要服务器侦听客户端尝试连接的端口。它们必须相同。

就此而言,您是否正在运行 searchd 服务器守护进程?在 windows 下通常将其安装为服务。

(并检查防火墙是否阻止访问 searchd 正在侦听的端口)

【讨论】:

  • 问题原来是,在我的表单输入字段中,我没有指定方法,所以它没有得到搜索查询输入。现在一切正常。只是一个nooby错误。非常感谢
  • @Pacemaker 酷。那你应该接受 Barryhunter 的回答!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 2016-10-25
  • 1970-01-01
  • 2014-09-13
相关资源
最近更新 更多