我遇到了sphinx配置和php api使用的问题(在Windows 7上)。
我已经配置了索引器:indexer --config sphinx.conf test1 并启动服务:searchd --install --config sphinx.conf 当我使用cmd控制台进行搜索时,我找到了结果,但是......没有使用php api。
此处出现错误:查询失败:无法读取搜索响应(状态= 2613,ver = 11830,len = 774976045,读取= 70)。
这是我的conf文件:
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source src1
{
type = mysql
sql_host = localhost
sql_user = root
sql_pass =
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, UNIX_TIMESTAMP(addTime) AS addTime, title, brand, material, size, description, c.name as categoryName \
FROM test \
JOIN category c ON c.id = advert.categoryId
sql_attr_uint = id
sql_attr_timestamp = addTime
sql_query_info = SELECT * FROM test WHERE id=$id
}
index catalog
{
source = src1
path = C:\wamp\www\sphinx\catalog
docinfo = extern
charset_type = utf-8
min_word_len = 3
min_prefix_len = 0
min_infix_len = 3
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = C:\wamp\www\sphinx\log\searchd.log
query_log = C:\wamp\www\sphinx\log\query.log
read_timeout = 5
max_children = 30
pid_file = C:\wamp\www\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:\wamp\www\sphinx\data
}
php文件:
<?php
include('sphinxapi.php');
//Sphinx
$s = new SphinxClient;
$s->setServer("localhost", 3306);
$s->setMatchMode(SPH_MATCH_EXTENDED2);
$result = $s->query("@title jean");
if ($result['total'] > 0) {
foreach ($result['matches'] as $id => $otherStuff) {
echo $id;
}
} else {
echo "Query failed: " . $s->GetLastError() . ".\n";
}
&GT;
答案 0 :(得分:2)
你在PHP脚本3306中指出 - 它是mysql服务器的端口:
$s->setServer("localhost", 3306);
尝试指向端口9312
同时尝试执行以下步骤:
删除已安装的Windows服务。
searchd --delete
使用配置文件的完整路径安装Windows服务
searchd --install --config fullPathToSphinx.conf
您需要手动运行服务或重启PC。要手动启动服务:从命令行程序services.msc
运行并在服务列表searchd
中查找并启动它。
答案 1 :(得分:1)
不要使用&#34; localhost&#34;在Windows上。
$ s-&gt; setServer(&#34; 127.0.0.1&#34;,9312);