From a6e585ed4a7b9d0f473888de8f30e70b835a09d5 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Tue, 1 Sep 2015 12:52:29 -0700 Subject: [PATCH] Expose the ability to change suggestion api's We want to run some tests with alternate suggestions algorithms. This allows code in the WikimediaEvents repository to replace the api call with its own method of generating suggestions. Related WikimediaEvents patch: I595db33 Bug: T111091 Change-Id: I1fab57ea3c0506b9b6183d214a29b978a388bc29 --- .../src/mediawiki/mediawiki.searchSuggest.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/resources/src/mediawiki/mediawiki.searchSuggest.js b/resources/src/mediawiki/mediawiki.searchSuggest.js index 5292e807ce..a20d7f077d 100644 --- a/resources/src/mediawiki/mediawiki.searchSuggest.js +++ b/resources/src/mediawiki/mediawiki.searchSuggest.js @@ -2,6 +2,20 @@ * Add search suggestions to the search form. */ ( function ( mw, $ ) { + mw.searchSuggest = { + request: function ( api, query, response, maxRows ) { + return api.get( { + action: 'opensearch', + search: query, + namespace: 0, + limit: maxRows, + suggest: '' + } ).done( function ( data ) { + response( data[ 1 ] ); + } ); + } + }; + $( function () { var api, map, searchboxesSelectors, // Region where the suggestions box will appear directly below @@ -172,15 +186,7 @@ api = api || new mw.Api(); - $.data( node, 'request', api.get( { - action: 'opensearch', - search: query, - namespace: 0, - limit: maxRows, - suggest: '' - } ).done( function ( data ) { - response( data[ 1 ] ); - } ) ); + $.data( node, 'request', mw.searchSuggest.request( api, query, response, maxRows ) ); }, cancel: function () { var node = this[0], -- 2.20.1