Hold number of search results in a data attribute
authorMikhail Popov <mpopov@wikimedia.org>
Thu, 13 Apr 2017 21:49:20 +0000 (14:49 -0700)
committerMikhail Popov <mpopov@wikimedia.org>
Wed, 19 Apr 2017 18:29:45 +0000 (11:29 -0700)
Current way of counting returned search results (e.g. for
Event Logging) relies on counting the appropriate elements
in the search results page's DOM, up to the limit the user
requested (e.g. 20 by default). This allows us to record
the total number and the offset, useful for event logging.
For example, if we wanted to know whether the user viewed
2nd or 3rd set of search results.

Change-Id: Ic8601e9eeddac84ba8e0d7dc6f127bf360b6f90f

includes/widget/search/SearchFormWidget.php

index a7407a0..008ed19 100644 (file)
@@ -103,7 +103,11 @@ class SearchFormWidget {
                if ( $totalResults > 0 && $offset < $totalResults ) {
                        $html .= Xml::tags(
                                'div',
-                               [ 'class' => 'results-info' ],
+                               [
+                                       'class' => 'results-info',
+                                       'data-mw-num-results-offset' => $offset,
+                                       'data-mw-num-results-total' => $totalResults
+                               ],
                                $this->specialSearch->msg( 'search-showingresults' )
                                        ->numParams( $offset + 1, $offset + $numResults, $totalResults )
                                        ->numParams( $numResults )