[英]How to show sphinx search result with php?
I installed sphinx search on localhost (wamp). 我在本地主机(沼泽)上安装了狮身人面像搜索。 I want to show results for example in one simple html table. 我想在一个简单的html表中显示结果。 I tried to connect with php to sphinx search, I think it done it, but when I printed the result it was 0.... but that was not true. 我试图用php连接到狮身人面像搜索,我认为它做到了,但是当我打印结果时它是0 ....但是那不是真的。 I do not really understand that in query part I need to put the word what I want to search? 我不太了解在查询部分是否需要输入要搜索的词? I tried search in command windows, it is good working, just I do not know how to show it on web page. 我尝试在命令窗口中进行搜索,但是效果很好,只是我不知道如何在网页上显示它。 And I want to use mysql. 而且我想使用mysql。 So my PHP looks like this: 所以我的PHP看起来像这样:
require ( "sphinx/api/sphinxapi.php" );
$s = new SphinxClient;
$s->setServer("localhost", 9306);
$s->setMatchMode(SPH_MATCH_ANY);
$s->setMaxQueryTime(3);
$result = $s->query("test");
var_dump($result);
Here is my mini conf file: 这是我的迷你conf文件:
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, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_query_info = SELECT * FROM documents WHERE id=$id
}
index test1
{
source = src1
path = C:/wamp/www/sphinx/data/test1
docinfo = extern
charset_type = sbcs
}
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
}
Your connection and a query might look like this: 您的连接和查询可能如下所示:
$link = mysql_connect ( '127.0.0.1:9306', '', '' );
$db_selected = mysql_select_db ( 'main', $link );
and then normally mysql queries (as you would do them normally) 然后通常是mysql查询(就像通常那样)
$sql = "select * from main WHERE MATCH('$queryterm') order by date desc LIMIT 0,50";
$result = mysql_query ( $sql );
Or you can retrieve some meta info if you want(see Sphinx document for the meta) 或者,您可以根据需要检索一些元信息(有关此元数据,请参见Sphinx文档)
$metainfo = mysql_query('SHOW META');
while ( $meta = mysql_fetch_array ( $metainfo ) ) {
$srchmeta[]=$meta;
//or whatever you want here
}
$s->setServer("localhost", 9306); $ s-> setServer(“ localhost”,9306);
Thats the mysql protocol port - sphinxQL. 多数民众赞成在mysql协议端口-sphinxQL。
In your config file you have sphinx listening on 9312 with the sphinxAPI protocol. 在您的配置文件中,您可以使用sphinxAPI协议在9312上监听sphinx。 So change your setServer line to use 9312 因此,更改您的setServer行以使用9312
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.