简体   繁体   English

如何计算狮身人面像的结果?

[英]How to count results in sphinx?

I have to deal with queries that have lots of results, but I only show them in sets of 20-30 rows. 我必须处理具有很多结果的查询,但是我只以20-30行为一组显示它们。

Then I use the SetLimits() method from the php API. 然后,我使用php API中的SetLimits()方法。

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. 我现在唯一能做到这一点的方法是通过将限制设置为10000000来获取所有结果,并查看sphinx返回的数组的“ total”键中的内容,但这不好,因为我只需要count( )号,我不希望使用狮身人面像来创建包含所有ID的巨大数组。

Performing a select..count() query in mysql won't work, because the indexed data in sphinx is always different. 在mysql中执行select..count()查询将不起作用,因为sphinx中的索引数据始终是不同的。

Any ideas? 有任何想法吗?

According to manual: SphinxClient::setLimits , 根据手册: 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. 我不是Sphinx开发人员,所以这只是一个盲目的猜测...它应避免出现大量结果而导致内存溢出。

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. 我还发现SELECT..COUNT()在Sphinx查询中不起作用,因此您是正确的。

Also, according to Sphinx documentation, you can retrive number of results using SHOW META query. 同样,根据Sphinx文档,您可以使用SHOW META查询来检索结果数量。

SHOW META 显示元

SHOW META shows additional meta-information about the latest query such as query time and keyword statistics: 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)

References: 参考文献:

Isn't SphinxClient:query returning data about how many records matched your request? SphinxClient:query是否返回有关符合您要求的记录数的数据?

"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. 据我了解,“总数”是此请求返回的条目数(受SetLimit影响),total_found是匹配查询的结果总数(不受SetLimit影响)。

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_%';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM