HappyDeveloper HappyDeveloper - 1 year ago 107
PHP Question

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.

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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download