我正在尝试为我的网站实施sphinx搜索,但mariadb的sphinx api和sphinxse没有返回任何结果。这些是我的配置:
source shops
{
type = mysql
sql_host = 127.0.0.1
sql_user = user
sql_pass = pass
sql_db = shop
sql_port = 3306 # optional, default is 3306
sql_query = SELECT id, site,price, title, content FROM p2
sql_attr_uint = price
sql_attr_string = site
sql_ranged_throttle = 0
}
index shops
{
source = shops
path = /path/
morphology = stem_en
min_word_len = 2
min_prefix_len = 0
min_infix_len = 3
}
这是我的索引结果:
# indexer shops --rotate
Sphinx 2.2.10-id64-release (2c212e0)
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
indexing index 'shops'...
collected 80645 docs, 162.1 MB
sorted 7.8 Mhits, 100.0% done
total 80645 docs, 162088951 bytes
total 8.568 sec, 18916136 bytes/sec, 9411.44 docs/sec
total 80655 reads, 0.045 sec, 0.3 kb/call avg, 0.0 msec/call avg
total 115 writes, 0.069 sec, 499.2 kb/call avg, 0.6 msec/call avg
rotating indices: successfully sent SIGHUP to searchd (pid=19340).
我的索引路径包含超过33 MB的数据,这似乎是公平的,索引器已经完成了它的工作
#restart sphinxsearchd
Copyright (c) 2001-2015, Andrew Aksyonoff
Copyright (c) 2008-2015, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file '/etc/sphinxsearch/sphinx.conf'...
listening on all interfaces, port=9312
listening on all interfaces, port=9306
precaching index 'shops'
precached 1 indexes in 0.022 sec
sphinxsearch is restarted.
这是我的php文件和结果:
require_once("sphinxapi.php");
$s = new SphinxClient;
$s->setServer("127.0.0.1", 9312);
$s->setMatchMode(SPH_MATCH_ANY);
$result = $s->Query($request->getParameter('s'));
print $s->GetLastError();
echo '<pre>';print_r($result);
结果:
Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => title
[1] => content
)
[attrs] => Array
(
[site] => 7
[price] => 1
)
[total] => 0
[total_found] => 0
[time] => 0.000
)