©
本文檔使用 php中文網手册 發布
(PECL sphinx >= 0.1.0)
SphinxClient::query — 执行搜索查询
$query
[, string $index
= "*"
[, string $comment
= ""
]] )连接到searchd服务器,根据服务器的当前设置执行给定的查询,取得并返回结果集.
query
查询字符串.
index
索引名称 (可以为多个,使用逗号分割,或者为“*”表示全部索引).
comment
发送到searchd的查询日志的注释内容
如果搜索成功, SphinxClient::query() 返回的结果集列表包含找到的全部匹配项中的一部分,以及与查询相关的统计数据. 结果集是哈希结构,包含如下键和值:
键 | 值说明 |
---|---|
"matches" | 存储文档ID以及其对应的另一个包含文档权重和属性值的hash表 |
"total" | 此查询在服务器检索所得的匹配文档总数(即服务器端结果集的大小,且与相关设置有关) |
"total_found" | (服务器上找到和处理了的)索引中匹配文档的总数 |
"words" | 将查询关键字(关键字已经过大小写转换,取词干和其他处理)映射到一个包含关于关键字的统计数据(“docs”——在多少文档中出现,“hits”——共出现了多少次)的小hash表上。 |
"error" | searchd报告的错误信息 |
"warning" | searchd报告的警告信息 |
[#1] design dot ber at gmail dot com [2015-09-12 05:26:45]
You can limit the search to certain indexes separated by anything other than letters, numbers, underscores, and dashes.
<?php
// All valid
$client->Query('test', 'main delta');
$client->Query('test', 'main;delta');
$client->Query('test', 'main, delta');
$client->Query('test', 'main:delta');
?>
[#2] moosh at php dot net [2011-02-14 03:35:02]
public array SphinxClient::query ( string $query [, string $index = "*" [, string $comment = "" ]] )
If you add a value for comment, you can retrieve them in sphinx query log.
[#3] php at senz dot su [2010-09-15 07:54:36]
There is also a "status" key showing in what status query has ended.
Here are codes, taken from searchd.cpp:
<?php
/// known status return codes
enum SearchdStatus_e
{
SEARCHD_OK = 0, ///< general success, command-specific reply follows
SEARCHD_ERROR = 1, ///< general failure, error message follows
SEARCHD_RETRY = 2, ///< temporary failure, error message follows, client should retry later
SEARCHD_WARNING = 3 ///< general success, warning message and command-specific reply follow
};
?>
[#4] fkoehl at gmail dot com [2008-12-11 08:16:19]
It appears that Query() (or the Sphinx program in general) does have some kind of limit imposed on the maximum length of a query submission. Stumbled across this limitation when trying to perform some searches based on content from user-submitted e-mails.
In looking at the returned array, the 'words' portion only accounts for the first 8 or 9 words of the long query. I'm assuming that the rest of the string is being truncated. The number of accepted words appears to change based on the total length of the words. Just a heads-up.