如何计算sphinx中的结果?

发布于 2024-11-01 22:28:37 字数 329 浏览 0 评论 0原文

我必须处理有大量结果的查询,但我只以 20-30 行为一组的形式显示它们。

然后我使用 php API 中的 SetLimits() 方法。

但我需要知道结果总数是多少,以计算页数(或结果集)。

我现在能做到这一点的唯一方法是将限制设置为 10000000 来提取所有结果,然后查看结果中的内容sphinx 返回的数组的“total”键,但这不好,因为我只需要 count() 数字,我不想 sphinx 创建一个包含所有 id 的巨大数组。

在mysql中执行select..count()查询是行不通的,因为sphinx中的索引数据总是不同的。

有什么想法吗?

I have to deal with queries that have lots of results, but I only show them in sets of 20-30 rows.

Then I use the SetLimits() method from the php API.

But I need to know what's the total number of results, to calculate the number of pages (or sets of results)

The only way I can do this right now is pulling all the results by setting the limit to 10000000 and see what is in the 'total' key of the array returned by sphinx, but this isn't good because I only need the count() number, I don't wan't sphinx to create a huge array with all the id's.

Performing a select..count() query in mysql won't work, because the indexed data in sphinx is always different.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风吹雪碎 2024-11-08 22:28:37

SphinxClient:query 是否返回有关有多少记录与您的请求匹配的数据?

据我了解,“total”是此请求返回的条目数(受 SetLimit 影响),total_found 是匹配查询的结果总数(不受 SetLimit 影响)。

Isn't SphinxClient:query returning data about how many records matched your request?

"total" is the number of entries returned by this request (affected by SetLimit) and total_found is the total number of results matching query (not affected by SetLimit) as I understand.

云淡风轻 2024-11-08 22:28:37

根据手册: SphinxClient::setLimits

问题

  $cl->SetLimits(0,0);

这应该可以解决我的 我不是 Sphinx 开发人员,所以这只是一个盲目的猜测......它应该避免记忆
大量结果溢出。

让我知道它是否有效,这样如果不正确,我可以删除答案。

我还发现 SELECT..COUNT() 在 Sphinx 查询中不起作用,所以你是对的。

此外,根据 Sphinx 文档,您可以使用 SHOW META 查询检索结果数量。

SHOW META

SHOW META 显示有关最新查询的其他元信息,例如查询时间和关键字统计信息:

mysql> SELECT * FROM test1 WHERE MATCH('test|one|two');
+------+--------+----------+------------+
| id   | weight | group_id | date_added |
+------+--------+----------+------------+
|    1 |   3563 |      456 | 1231721236 |
|    2 |   2563 |      123 | 1231721236 |
|    4 |   1480 |        2 | 1231721236 |
+------+--------+----------+------------+
3 rows in set (0.01 sec)

mysql> SHOW META;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total         | 3     |
| total_found   | 3     |
| time          | 0.005 |
| keyword[0]    | test  |
| docs[0]       | 3     |
| hits[0]       | 5     |
| keyword[1]    | one   |
| docs[1]       | 1     |
| hits[1]       | 2     |
| keyword[2]    | two   |
| docs[2]       | 1     |
| hits[2]       | 2     |
+---------------+-------+
12 rows in set (0.00 sec)

参考:

According to manual: SphinxClient::setLimits,

This should do the trick

  $cl->SetLimits(0,0);

I'm not Sphinx developer, so this is just a blind guess... It should avoid memory
overflow with large number of results.

Let me know does it work so I can remove answer if this is not correct.

I've also found that SELECT..COUNT() doesn't work in Sphinx query, so you're right about that.

Also, according to Sphinx documentation, you can retrive number of results using SHOW META query.

SHOW META

SHOW META shows additional meta-information about the latest query such as query time and keyword statistics:

mysql> SELECT * FROM test1 WHERE MATCH('test|one|two');
+------+--------+----------+------------+
| id   | weight | group_id | date_added |
+------+--------+----------+------------+
|    1 |   3563 |      456 | 1231721236 |
|    2 |   2563 |      123 | 1231721236 |
|    4 |   1480 |        2 | 1231721236 |
+------+--------+----------+------------+
3 rows in set (0.01 sec)

mysql> SHOW META;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| total         | 3     |
| total_found   | 3     |
| time          | 0.005 |
| keyword[0]    | test  |
| docs[0]       | 3     |
| hits[0]       | 5     |
| keyword[1]    | one   |
| docs[1]       | 1     |
| hits[1]       | 2     |
| keyword[2]    | two   |
| docs[2]       | 1     |
| hits[2]       | 2     |
+---------------+-------+
12 rows in set (0.00 sec)

References:

魂牵梦绕锁你心扉 2024-11-08 22:28:37
SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM information_schema.GLOBAL_STATUS WHERE
VARIABLE_NAME LIKE 'SPHINX_TOTAL_FOUND';

了解更多信息

SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM information_schema.GLOBAL_STATUS WHERE
VARIABLE_NAME LIKE 'SPHINX_%';
SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM information_schema.GLOBAL_STATUS WHERE
VARIABLE_NAME LIKE 'SPHINX_TOTAL_FOUND';

for more info

SELECT VARIABLE_NAME, VARIABLE_VALUE
FROM information_schema.GLOBAL_STATUS WHERE
VARIABLE_NAME LIKE 'SPHINX_%';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文