1

How can I get the total number of results on a Search API View that has a limit of 5 results to display?

Some more info: I have to make a bit more complex search where several attachments are combined on a page as a groups of results. Every group should show just the first 5 results, but also a link "see all XX results". I'm using Search API + Solr, Views with exposed fulltext search. If I use "Global: Results summary" in header or footer, it will show maximum the limit of 5 as a number.

edit 1

Search API Solr returns 'numFound' which is what I need, but how do I use it in Views?

4
  • I don't know if it will work on groups or totals like the Global, but you could look at Views Calc module (drupal.org/project/views_calc)
    – Geoff
    Commented Oct 8, 2014 at 3:23
  • Unfortunately, Views Calc cannot do the job.
    – kufeiko
    Commented Oct 8, 2014 at 10:43
  • Couldn't this be done with the "Pager" option?
    – Beebee
    Commented Oct 8, 2014 at 10:57
  • @Beebee Unfortunately no, as this is already an attachment and it doesn't allow its own pager.
    – kufeiko
    Commented Oct 8, 2014 at 11:23

3 Answers 3

5

So after a day, here's the result:

As J. Reynolds suggested, I finished up using $view->total_rows, but:

  • To populate $views->total_rows, you have to use a pager in your view - that was not an option with the attachments.
  • If you don't use a pager, you could force populating $view->total_rows by altering the View query before its execution like this:
    function mycustommodule_views_pre_execute(&$view) {
      $view->get_total_rows = TRUE;
    }

And after that you have that $view->total_rows!

2

Try with this type of code. You can select either attachment_before or attachment_after, and if the placement is not to your liking you may alter the views template to suit. I know this works with a normal view and I don't see why it would not work with a Search API result. And I think you can place it in a theme's template.php file if you prefer rather than a module.

function MYMODULE_views_post_execute(&$view){
    if ($view->name == "MACHINENAME_OF_VIEW") { // can slso check for display if need be
        $view->attachment_before .= <div class="result">$view->total_rows</div>
    }
}
1
  • Thanks for the suggestion, but $view->total_rows appears to be empty :(
    – kufeiko
    Commented Oct 8, 2014 at 13:02
1

By configure Views Global result summary in header or Footer, we can display Total number of results.

Search with result summary in Header and pass the ​tokens,

@start -- the initial record number in the set @end -- the last record number in the set @total -- the total records in the set @label -- the human-readable name of the view @per_page -- the number of items per page @current_page -- the current page number @current_record_count -- the current page record count @page_count -- the total page count

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.