Page MenuHomePhabricator
Paste P1923

WikibaseSearchApi
ActivePublic

Authored by Bene on Aug 25 2015, 11:31 AM.
Tags
None
Referenced Files
F2359347: WikibaseSearchApi
Aug 25 2015, 1:08 PM
F2358250: WikibaseSearchApi
Aug 25 2015, 11:31 AM
/**
* API for search
* @extends Api
* @class SearchApi
*/
( function ( M, $ ) {
var WikibaseSearchApi,
Page = M.require( 'Page' ),
SearchApi = M.require( 'modules/search/SearchApi' );
/**
* @class WikibaseSearchApi
* @extends SearchApi
*/
WikibaseSearchApi = SearchApi.extend( {
/**
* Get the data used to do the search query api call.
* @method
* @param {String} query to search for
* @return {Object}
*/
getApiData: function ( query ) {
return {
action: 'wbsearchentities',
language: mw.config.get( 'wgUserLanguage' ), //FIXME
search: query,
format: 'json',
type: 'item' //FIXME
};
},
/**
* Process the data returned by the api call.
* @param {String} query to search for
* @param {Object} data from api
* @return {Array}
* @private
*/
_processData: function( query, data ) {
var self = this,
results = [];
if ( data.search ) {
$.each( data.search, function ( i, entity ) {
// data used for creating {Page} objects
results.push( {
id: entity.pageid, //FIXME
title: entity.title, //FIXME
displayTitle: self._highlightSearchTerm( entity.label, query ),
url: entity.url,
thumbnail: entity.thumbnail //FIXME
} );
} );
}
return results;
}
} );
M.define( 'modules/search/WikibaseSearchApi', WikibaseSearchApi );
}( mw.mobileFrontend, jQuery ) );

Event Timeline

Bene changed the title of this paste from untitled to WikibaseSearchApi.
Bene updated the paste's language from autodetect to js.

@Bene

displayTitle could / should be set to the matched term instead of always the label?
Otherwise sometimes results could be confusing.

Would be nice to actually be able to show more than 1 thing here, but meh...

We could add the matched term in brackets behind the label, but that seems to be even hackier :S

My only reason for saying the above is otherwise you could search for "Foo" but instead be shown "ABCDE" in the list (as a random example)....

Looks good in general prepare a patch?

I will prepare a patch as soon as T110069 is resolved