Count the number of results found on a search asset

(Nick Papadatos) #1

Matrix Version: 5.5

I know I’m asking a fairly basic question here but how does one get the following result count on a search asset??

1 - 10 of 257 results found then the next page wouyld be 2 - 20 of 257 results found etc

So I can do a globals get page for the first number (or use %current_result_page%) and %result_count% for the total number but am stuck with the middle

Any ideas would be appreciated

(Nick Papadatos) #2

I think I may be able to answer my own question here but is this how it’s done?

page: %current_result_page% - %page_number^multiply:10% of %result_count% results found

the ^multiply:10 is the fact I’m show 10 at a time - seems to be working though…

(John gill) #3

Interesting that Search Page doesn’t have the %first_asset_position% and
%last_asset_position% keywords that Asset Listing Page has .

I think you’re right that you need keyword maths to make it happen, and you need to hardcode the page size which is a shame but probably ok. You’re definitely on the right track, but:

  • you need some maths to turn the current page number to the “first index of this page”, and
  • Your solution for the end date would show 260 on the last page, not 257, so you need to compare it to %result_count% to make sure it doesn’t go over.

This seems to work

%current_result_page^subtract:1^multiply:20^add:1% - %current_result_page^multiply:20^gt:{result_count}:{result_count}:{current_result_page^multiply:20}%

The index of the start of the current page is (page - 1) * 20 + 1.

The index of the end of the current page is page * 20 unless that is larger than result_count, in which case use result_count instead.

(Aleks Bochniak) #4

Is the number of results per page customisable by the user? If so, then you’re better off just using GET vars for this

(Nick Papadatos) #5

Thanks Aleks,
No, not customisable by the user but all good, page numbering working for me as expected.