Page MenuHomePhabricator

Implement `SimilarArticleLookup` using the Action API
Open, Needs TriagePublic

Description

Background: The event discovery flow needs to expand the set of page titles checked
against worklists beyond the article the editor just saved. We use CirrusSearch's morelike:
feature to find topically similar articles via the Action API (`action=query&list=search&
srsearch=morelike:{title}). A direct SearchEngineFactory` call is not viable because
CirrusSearch availability cannot be guaranteed across all deployment environments —
development wikis typically run without it. Routing the lookup through the Action API
(using HttpRequestFactory) decouples the feature from the local search configuration.
A config variable allows development environments
to point at a real wiki (e.g. en.wikipedia.org) rather than their local API.

NOTE: we might want to look deeper into this and see if there is a way to use SearchEngineFactory directly

Type of story

  • Backend

Acceptance criteria

  • A SimilarArticleLookup service is implemented, injectable via the MediaWiki DI container.
  • It accepts a prefixed article title and a result limit and returns a list of similar prefixed titles by querying morelike:{title} via HttpRequestFactory.
  • The API base URL is read from CampaignEventsSimilarArticlesApiBaseUrl (nullable config); when null it defaults to the local wiki's api.php.
  • The source article is excluded from its own results.
  • HTTP errors, non-200 responses, and malformed payloads are handled gracefully: log and return an empty array; do not throw.

Testing required?

  • Yes
  • Minimum to pass QA: unit tests cover normal results, empty results, HTTP error response, and malformed response body; HttpRequestFactory is mocked — no real HTTP calls in tests.