如何计算sphinx中的结果?
我必须处理有大量结果的查询,但我只以 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
根据手册: SphinxClient::setLimits,
问题
这应该可以解决我的 我不是 Sphinx 开发人员,所以这只是一个盲目的猜测......它应该避免记忆
大量结果溢出。
让我知道它是否有效,这样如果不正确,我可以删除答案。
我还发现
SELECT..COUNT()
在 Sphinx 查询中不起作用,所以你是对的。此外,根据 Sphinx 文档,您可以使用 SHOW META 查询检索结果数量。
SHOW META
SHOW META 显示有关最新查询的其他元信息,例如查询时间和关键字统计信息:
参考:
According to manual: SphinxClient::setLimits,
This should do the trick
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:
References:
了解更多信息
for more info