Jdrewniak has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/373049 )
Change subject: [WIP] Search thumbnails AB test
......................................................................
[WIP] Search thumbnails AB test
AB test that adds thumbnails to Special:Search results
Bug: T149811
Change-Id: I64dee665270ec6a0ece0c293f8d1667e27a01d46
---
M extension.json
M modules/ext.wikimediaEvents.searchSatisfaction.js
A modules/ext.wikimediaEvents.searchThumbnails.js
3 files changed, 119 insertions(+), 9 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents
refs/changes/49/373049/1
diff --git a/extension.json b/extension.json
index 22f3a14..66f95bd 100644
--- a/extension.json
+++ b/extension.json
@@ -197,6 +197,14 @@
"mediawiki.Uri"
]
},
+ "ext.wikimediaEvents.searchThumbnails": {
+ "scripts": [
+
"ext.wikimediaEvents.searchThumbnails.js"
+ ],
+ "dependencies": [
+ "mediawiki.ForeignApi"
+ ]
+ },
"ext.wikimediaEvents.humanSearchRel": {
"messages": [
"wikimediaevents-humanrel-question-a",
diff --git a/modules/ext.wikimediaEvents.searchSatisfaction.js
b/modules/ext.wikimediaEvents.searchSatisfaction.js
index b1f1c78..d83ebb9 100644
--- a/modules/ext.wikimediaEvents.searchSatisfaction.js
+++ b/modules/ext.wikimediaEvents.searchSatisfaction.js
@@ -113,12 +113,8 @@
function initialize( session ) {
var sessionId = session.get( 'sessionId' ),
- // LTR sub test
- // Test is running on enwiki only, which
reports ~14k sessions per day
- // at the 1:2000 sampling. Sampling increased
to 1:500, so 56k sessions
- // per day. Those 56k sessions will be split
15k to dashboards, and
- // 7k per bucket, for ~50k per bucket in a week.
- validBuckets = [ 'control', 'ltr-20',
'ltr-i-20', 'ltr-1024', 'ltr-i-1024', 'ltr-i-20-1024' ],
+ // Thumbnail subtest
+ validBuckets = [ 'serp_no_thumbnails',
'serp_add_thumbnails' ],
sampleSize = ( function () {
var dbName = mw.config.get( 'wgDBname'
),
// Provides a place to handle
wiki-specific sampling,
@@ -140,8 +136,8 @@
subTest: null
},
enwiki: {
- test: 80,
- subTest: 0.96
+ test: 200,
+ subTest: 0.5
},
enwiktionary: {
test: 40,
@@ -775,6 +771,11 @@
serpExtras.teamDraft = mw.config.get(
'wgCirrusSearchTeamDraft' );
}
+ // thumb AB test
+ if ( session.get( 'subTest' ) ===
'explore_similar_test' ) {
+ mw.loader.load(
'ext.wikimediaEvents.searchThumbnails' );
+ }
+
params = {
query: mw.config.get( 'searchTerm' ),
hitsReturned: $( '.results-info' ).data(
'mw-num-results-total' ),
@@ -799,7 +800,23 @@
params.inputLocation = didYouMeanMap[
search.didYouMean ];
}
- logEvent( 'searchResultPage', params );
+ /**
+ * Thumbnail AB Test
+ * For the Thumbnail AB test, the initial
'searchResultPage' event is
+ * sent after the 'thumbsLoaded' event (which calls the
API) is complete.
+ * This delays the 'searchResultPage' event but is
necessary for including the
+ * thumbnail info in the event.
+ **/
+ if ( session.get( 'subTest' ) ===
'explore_similar_test' ) {
+ mw.trackSubscribe(
'ext.wikimediaEvents.searchThumbnails.thumbsLoaded', function ( topic, data ) {
+ var extraParams = JSON.parse(
params.extraParams );
+ extraParams.thumbnailPositions = data;
+ params.extraParams = JSON.stringify(
extraParams );
+ logEvent( 'searchResultPage', params );
+ } );
+ } else {
+ logEvent( 'searchResultPage', params );
+ }
}
if ( search.cameFromSearch ) {
logEvent( 'visitPage', {
diff --git a/modules/ext.wikimediaEvents.searchThumbnails.js
b/modules/ext.wikimediaEvents.searchThumbnails.js
new file mode 100644
index 0000000..1722f5a
--- /dev/null
+++ b/modules/ext.wikimediaEvents.searchThumbnails.js
@@ -0,0 +1,85 @@
+/**
+ * Javascript module for adding thumbnails to Special:Search Search results.
+ * This modules uses client-side javascript and the mediawiki API to add
thumbnails.
+ * It was created for testing purposes to measure the impact of thumbnails on
search
+ * results.
+ *
+ * This module itself does not log any events, but is meant to be used with
the search
+ * Satisfaction schema to perform AB tests.
+ */
+
+( function ( $, mw ) {
+ var api = new mw.ForeignApi( 'https://en.wikipedia.org/w/api.php', {
anonymous: true } ), // for this test, assuming mw.API is loaded on
SpecialSearch on desktop
+ $results = $( '.mw-search-results li' ),
+ resultsCount = $results.length,
+ queryTitles = [];
+
+ // Only run on specialSearch page with default profile
+ if ( mw.config.get( 'wgCanonicalSpecialPageName' ) !== 'Search' ||
+ ( mw.util.getParamValue( 'profile' ) !== 'default' &&
+ mw.util.getParamValue( 'profile' ) !== null ) || // no param is
the default profile
+ resultsCount === 0
+ ) {
+ return;
+ }
+
+ $results.each( function ( i, el ) {
+ var title = $( el ).find( '.mw-search-result-heading > a'
).attr( 'title' );
+ queryTitles.push( title.replace( ' (page does not exist)', '' )
);
+ } );
+
+ function appendThumbnail( el, thumb ) {
+ $( el ).children( '.searchresult' ).prepend( thumb );
+ }
+
+ function createThumbnail( url ) {
+ if ( url ) {
+ return $( '<div/>' ).css( {
+ 'border-radius': '2px',
+ 'margin-right': '0.5em',
+ 'float': 'left',
+ width: '4em',
+ height: '4em',
+ 'background-size': 'cover',
+ 'margin-top': '0.3em',
+ 'background-image': 'url(' + url + ')'
+ } );
+ }
+ }
+
+ function processThumbs( data ) {
+ var resultsWithThumbs = [];
+ if ( data.query && data.query.pages ) {
+ data.query.pages.forEach( function ( page ) {
+ var title, thumb, el;
+ if ( page.thumbnail ) {
+ title = page.title;
+ thumb = createThumbnail(
page.thumbnail.source );
+ el = $results.get( queryTitles.indexOf(
title ) );
+ appendThumbnail( el, thumb );
+ resultsWithThumbs.push( $( el ).find(
'.mw-search-result-heading a' ).data( 'serp-pos' ) );
+ }
+ } );
+ }
+ return resultsWithThumbs;
+ }
+
+ function emitCustomEvent( resultsWithThumbs ) {
+ mw.track( 'ext.wikimediaEvents.searchThumbnails.thumbsLoaded',
resultsWithThumbs.sort( function ( a, b ) { return a > b; } ) );
+ }
+
+ api.get( {
+ action: 'query',
+ format: 'json',
+ prop: 'pageimages',
+ titles: queryTitles,
+ formatversion: 2,
+ piprop: 'thumbnail',
+ pilicense: 'any',
+ pithumbsize: 200,
+ origin: '*'
+ } )
+ .then( processThumbs )
+ .then( emitCustomEvent );
+
+}( jQuery, mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/373049
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I64dee665270ec6a0ece0c293f8d1667e27a01d46
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: Jdrewniak <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits