Expose the ability to change suggestion api's
authorErik Bernhardson <ebernhardson@wikimedia.org>
Tue, 1 Sep 2015 19:52:29 +0000 (12:52 -0700)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 2 Sep 2015 02:23:41 +0000 (19:23 -0700)
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

resources/src/mediawiki/mediawiki.searchSuggest.js

index 5292e80..a20d7f0 100644 (file)
@@ -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
 
                                        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],