EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/270863
Change subject: [WIP] Add autocomplete to search satisfaction schema
......................................................................
[WIP] Add autocomplete to search satisfaction schema
Mostly ready, but is missing functionality to identify if the backend
performed a prefix or completion search.
* Adds a 'source' field distinguishing events as coming from
autocomplete or full text search.
* Recreate all full text events for autocomplete
Bug: T125915
Change-Id: I5438373ed0c53ff524aea4b0548cd850c7e00e92
---
M extension.json
M modules/ext.wikimediaEvents.searchSatisfaction.js
2 files changed, 95 insertions(+), 11 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaEvents
refs/changes/63/270863/1
diff --git a/extension.json b/extension.json
index 4841f5c..eb00e4e 100644
--- a/extension.json
+++ b/extension.json
@@ -101,7 +101,7 @@
"schema.TestSearchSatisfaction2": {
"class": "ResourceLoaderSchemaModule",
"schema": "TestSearchSatisfaction2",
- "revision": 14098806
+ "revision": 15344952
},
"schema.GeoFeatures": {
"class": "ResourceLoaderSchemaModule",
diff --git a/modules/ext.wikimediaEvents.searchSatisfaction.js
b/modules/ext.wikimediaEvents.searchSatisfaction.js
index 6a4651a..013bb38 100644
--- a/modules/ext.wikimediaEvents.searchSatisfaction.js
+++ b/modules/ext.wikimediaEvents.searchSatisfaction.js
@@ -25,7 +25,7 @@
return;
}
- var search, session,
+ var search, autoComplete, session,
isSearchResultPage = mw.config.get( 'wgIsSearchResultPage' ),
uri = new mw.Uri( location.href ),
checkinTimes = [ 10, 20, 30, 40, 50, 60, 90, 120, 150, 180,
210, 240, 300, 360, 420 ],
@@ -49,6 +49,10 @@
}
search = initFromWprov( 'srpw1_' );
+ autoComplete = initFromWprov( 'acrw1_' );
+ // with no position appended indicates the user submitted the
+ // autocomplete form.
+ autoComplete.cameFromAutocomplete = uri.query.wprov === 'acrw1';
// Cleanup the location bar in supported browsers.
if ( uri.query.wprov && window.history.replaceState ) {
@@ -62,7 +66,7 @@
storageNamespace = 'wmE-sS-',
// persistent state keys that have a lifetime
ttl = {
- sessionId: 10 * 60 * 1000,
+ sessionId: 86400000, // longer session for
debugging 10 * 60 * 1000,
token: 24 * 60 * 60 * 1000
},
now = new Date().getTime();
@@ -230,12 +234,14 @@
setTimeout( action, 1000 * timeout );
}
- function genLogEventFn( session ) {
+ function genLogEventFn( source, session ) {
return function ( action, extraData ) {
var scrollTop = $( window ).scrollTop(),
evt = {
// searchResultPage, visitPage or
checkin
action: action,
+ // source of the action, either search
or autocomplete
+ source: source,
// identifies a single user performing
searches within
// a limited time span.
searchSessionId: session.get(
'sessionId' ),
@@ -282,7 +288,7 @@
* @param {SessionState} session
*/
function setupSearchTest( session ) {
- var logEvent = genLogEventFn( session );
+ var logEvent = genLogEventFn( 'fulltext', session );
if ( isSearchResultPage ) {
// When a new search is performed reset the session
lifetime.
@@ -309,15 +315,93 @@
}
/**
- * Logic starts here.
+ * Sets up the autocomplete search test.
+ *
+ * It will log events and will put an attribute on some links
+ * to track user satisfaction.
+ *
+ * @param {SessionState} session
*/
- if ( isSearchResultPage || search.cameFromSearch ) {
- $( document ).ready( function () {
- session = new SessionState( 'search' );
- if ( session.get( 'enabled' ) ) {
- setupSearchTest( session );
+ function setupAutocompleteTest( session ) {
+ var logEvent = genLogEventFn( 'autocomplete', session );
+
+ if ( autoComplete.cameFromSearch ) {
+ logEvent( 'visitPage', {
+ position: autoComplete.resultPosition
+ } );
+ interval( checkinTimes, function ( checkin ) {
+ logEvent( 'checkin', {
+ checkin: checkin
+ } );
+ } );
+ }
+
+ mw.trackSubscribe( 'mediawiki.searchSuggest', function ( topic,
data ) {
+ if ( data.action === 'impression-results' ) {
+ // When a new search is performed reset the
session lifetime.
+ session.refresh( 'sessionId' );
+
+ // run every time an autocomplete result is
shown
+ logEvent( 'searchResultPage', {
+ hitsReturned: data.numberOfResults,
+ query: data.query,
+ inputLocation: data.inputLocation
+ } );
+ } else if ( data.action === 'render-one' ) {
+ // run when rendering anchors for suggestion
results. Attaches a wprov
+ // to the link so we know when the user arrives
they came from autocomplete
+ // and what position they clicked.
+ data.formData.linkParams.wprov =
autoComplete.wprovPrefix + data.index;
}
+
} );
}
+ function setup( fn ) {
+ session = session || new SessionState();
+
+ if ( session.get( 'enabled' ) ) {
+ fn( session );
+ }
+ }
+
+ /**
+ * Decorator to call the inner function at most one time.
+ *
+ * @param {Function} fn
+ * @return {Function}
+ */
+ function atMostOnce( fn ) {
+ var called = false;
+ return function () {
+ if ( !called ) {
+ fn();
+ called = true;
+ }
+ };
+ }
+
+ // Full text search satisfaction tracking
+ if ( isSearchResultPage || search.cameFromSearch ) {
+ $( document ).ready( function () {
+ setup( setupSearchTest );
+ } );
+ }
+
+ // Autocomplete satisfaction tracking
+ $( document ).ready( function () {
+ if ( autoComplete.cameFromSearch ) {
+ // user came here by selecting an autocomplete result,
+ // initialize on page load
+ setup( setupAutocompleteTest );
+ } else {
+ // delay initialization until the user clicks into
+ // the autocomplete box. Note this is one per element
+ // and not one ever, hence the decorator.
+ $( 'input[type=search]' ).one( 'focus', atMostOnce(
function () {
+ setup( setupAutocompleteTest );
+ } ) );
+ }
+ } );
+
}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/270863
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5438373ed0c53ff524aea4b0548cd850c7e00e92
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaEvents
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits