Jonas Kress (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/341509 )
Change subject: Use fulltext search in commons suggester ...................................................................... Use fulltext search in commons suggester Also uses content model to filter for geo-shapes Bug:T57549 Change-Id: I4665a4328d0d1ed5883d18b4c063b166503e4fd4 --- M lib/jquery.ui/jquery.ui.commonssuggester.js M src/experts/CommonsMediaType.js M src/experts/GeoShape.js 3 files changed, 34 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/data-values/value-view refs/changes/09/341509/1 diff --git a/lib/jquery.ui/jquery.ui.commonssuggester.js b/lib/jquery.ui/jquery.ui.commonssuggester.js index 1ed8bed..fe6a2bf 100644 --- a/lib/jquery.ui/jquery.ui.commonssuggester.js +++ b/lib/jquery.ui/jquery.ui.commonssuggester.js @@ -26,7 +26,8 @@ */ options: { ajax: $.ajax, - namespace: null + namespace: null, + contentModel: null }, /** @@ -56,14 +57,17 @@ url: 'https://commons.wikimedia.org/w/api.php', dataType: 'jsonp', data: { - search: self._grepFileTitleFromTerm( term ), - action: 'opensearch', - namespace: NAMESPACE[self.options.namespace] || NAMESPACE.File + action: 'query', + srsearch: self._getSearchString( term ), + srnamespace: NAMESPACE[self.options.namespace] || '*', + srlimit: 10, + list: 'search', + format: 'json' }, timeout: 8000 } ) .done( function( response ) { - deferred.resolve( response[1], term ); + deferred.resolve( response.query.search, term ); } ) .fail( function( jqXHR, textStatus ) { // Since this is a JSONP request, this will always fail with a timeout... @@ -72,6 +76,22 @@ return deferred.promise(); }; + }, + + /** + * @private + * + * @param {string} term + * @return {string} + */ + _getSearchString: function( term ) { + var searchString = this._grepFileTitleFromTerm( term ); + + if ( this.options.contentModel ) { + searchString += ' contentmodel:' + this.options.contentModel; + } + + return searchString; }, /** @@ -102,14 +122,13 @@ * @return {jQuery.ui.ooMenu.Item} */ _createMenuItemFromSuggestion: function( suggestion, requestTerm ) { - suggestion = suggestion.replace( /^File:/, '' ); - - var label = suggestion; - - if ( requestTerm ) { - label = util.highlightSubstring( requestTerm, suggestion ); - } - + var suggestion = suggestion.title.replace( /^File:/, '' ), + label = util.highlightSubstring( + requestTerm, + suggestion, { + caseSensitive: false, + withinString: true + } ); return new $.ui.ooMenu.Item( label, suggestion ); } diff --git a/src/experts/CommonsMediaType.js b/src/experts/CommonsMediaType.js index 55c5153..aec60b3 100644 --- a/src/experts/CommonsMediaType.js +++ b/src/experts/CommonsMediaType.js @@ -26,7 +26,7 @@ var notifier = this._viewNotifier, $input = this.$input; - $input.commonssuggester(); + $input.commonssuggester( { namespace: 'File' } ); // Using the inputautoexpand plugin, the position of the dropdown needs to be updated // whenever the input box expands vertically: diff --git a/src/experts/GeoShape.js b/src/experts/GeoShape.js index 4fbd8d7..68d63f1 100644 --- a/src/experts/GeoShape.js +++ b/src/experts/GeoShape.js @@ -26,7 +26,7 @@ var notifier = this._viewNotifier, $input = this.$input; - $input.commonssuggester( { namespace: 'Data' } ); + $input.commonssuggester( { namespace: 'Data', contentModel: 'Map.JsonConfig' } ); // Using the inputautoexpand plugin, the position of the dropdown needs to be updated // whenever the input box expands vertically: -- To view, visit https://gerrit.wikimedia.org/r/341509 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4665a4328d0d1ed5883d18b4c063b166503e4fd4 Gerrit-PatchSet: 1 Gerrit-Project: data-values/value-view Gerrit-Branch: master Gerrit-Owner: Jonas Kress (WMDE) <jonas.kr...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits