Include additional analytics in Special:Search
authorErik Bernhardson <ebernhardson@wikimedia.org>
Thu, 24 Sep 2015 20:35:25 +0000 (13:35 -0700)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Mon, 28 Sep 2015 22:10:07 +0000 (15:10 -0700)
* Adds query performed to javascript config, to be picked up by
  the TestSearchSatisfaction schema.

* Adds data-serp-pos attribute to serach result anchors.
  This is picked up by the TestSearchSatisfaction schema
  and appended to urls (when participating in the test)
  as the `wprov` query parameter.

Bug: T113291
Change-Id: Ia0e8a955806e225e2f5a500e9290145895737274

includes/specials/SpecialSearch.php

index 06cad42..28769ec 100644 (file)
@@ -115,6 +115,7 @@ class SpecialSearch extends SpecialPage {
                        return;
                }
 
+               $out->addJsConfigVars( array( 'searchTerm' => $search ) );
                $this->searchEngineType = $request->getVal( 'srbackend' );
 
                if ( $request->getVal( 'fulltext' )
@@ -440,7 +441,7 @@ class SpecialSearch extends SpecialPage {
                        $stParams
                );
 
-               # html of did you mean... search suggestion link
+               # HTML of did you mean... search suggestion link
                return Html::rawElement(
                        'div',
                        array( 'class' => 'searchdidyoumean' ),
@@ -648,8 +649,9 @@ class SpecialSearch extends SpecialPage {
 
                $out = "<ul class='mw-search-results'>\n";
                $result = $matches->next();
+               $pos = $this->offset;
                while ( $result ) {
-                       $out .= $this->showHit( $result, $terms );
+                       $out .= $this->showHit( $result, $terms, ++$pos );
                        $result = $matches->next();
                }
                $out .= "</ul>\n";
@@ -665,10 +667,11 @@ class SpecialSearch extends SpecialPage {
         *
         * @param SearchResult $result
         * @param array $terms Terms to highlight
+        * @param int $position Position within the search results, including offset.
         *
         * @return string
         */
-       protected function showHit( $result, $terms ) {
+       protected function showHit( $result, $terms, $position ) {
 
                if ( $result->isBrokenTitle() ) {
                        return '';
@@ -689,7 +692,8 @@ class SpecialSearch extends SpecialPage {
 
                $link = Linker::linkKnown(
                        $link_t,
-                       $titleSnippet
+                       $titleSnippet,
+                       array( 'data-serp-pos' => $position ) // HTML attributes
                );
 
                //If page content is not readable, just return the title.