Page MenuHomePhabricator

Create Rest API for SearchVue article data
Closed, ResolvedPublic

Description

SearchVue currently performs requests against MW's action API, combining data from multiple modules.
As indicated in T307736#8348021, those are not cached.

We should create a new rest.php entrypoint from within SearchVue for the article data.
See https://www.mediawiki.org/wiki/API:REST_API/Extensions for instructions about setting up a new Rest API endpoint.

Instead of reimplementing all logic, this new API can simply wrap around the current request (which would now be performed on the backend) and filter out any data not needed.

Essentially something along the lines of:

$request = new FauxRequest( [
	'action' => 'query',
	'format' => 'json',
	'titles' => $title,
	'prop' => 'pageimages|pageprops|cirrusdoc',
	'formatversion' => 2,
	'pithumbsize' => 400,
	'pilicense' => 'free',
	'piprop' => 'thumbnail|name|original',
	'cdincludes' => 'heading'
] );
$api = new ApiMain( $request );
$context = new DerivativeContext( RequestContext::getMain() );
$context->setRequest( $request );
$api->setContext( $context );
$api->execute();
$response = $api->getResult()->getResultData( [], [ 'Strip' => 'all' ] );
// @todo filter unused fields from response (if any)

(See https://github.com/wikimedia/mediawiki-extensions-MediaSearch/blob/master/src/Special/SpecialMediaSearch.php#L548 for something similar)

Variables for the page endpoint are:

  • page title
  • elastic field from which the search snippet originated (unused ATM, but will need this for T316397)

So that endpoint could be something like rest.php/searchvue/v0/page/{page_title}/{snippet_field}

Event Timeline

Tagging as Milestone 2. Since it was up during performance review, I am interpreting this to be a blocker for initial deployment - if it is not, please remove the tag.

Change 865032 had a related patch set uploaded (by Simone Cuomo; author: Simone Cuomo):

[mediawiki/extensions/SearchVue@master] Create Rest API for SearchVue article data

https://gerrit.wikimedia.org/r/865032

Change 865032 merged by jenkins-bot:

[mediawiki/extensions/SearchVue@master] Create Rest API for SearchVue article data

https://gerrit.wikimedia.org/r/865032

I can confirm that this is done and deployed. All information surfacing the Search Preview are coming from our newly created API, the FE API ha been removed as part of this ticket