It does not seem desired to have knowledge on CirrusSearch/Elastic encoded in Wikibase. It definitely is valuable to allow Elastic/Cirrus-powered search in Wikibase, but Wikibase itself should not be depending on CirrusSearch, or Elastic in any way. Similarly, CirrusSearch extension should not know that Wikibase even exists, as one of its possible users, but still both CirrusSearch and Wikibase would enable a powerful application.
Having such separation would allow more efficient development of both Wikibase, and CirrusSearch. Having clear boundaries would also improve the work on Cirrus-powered searched for Wikibase/Wikidata, as in my opinion, it would provide the area within which this work can be done, without a need to adjust Wikibase and/or CirrusSearch for the need of this specific topic (I mean that both CirrusSearch and Wikibase do far more than just Cirrus-based search in Wikibase).
I suggest the following way to make the separation: the CirrusSearch/Elastcic-specific code would be moved to a separate extension (also meaning it would be moved to its dedicated code repository). This extension would be enabled on wikis that use Wikibase, and the Cirrus-based search (e.g. wikidata.org). The extension would be owned by WMF's Search Platform team.
In practice, the separation would mean:
- moving code from the Wikibase\Repo\Search\Elastic namespace to the new extension
- also moving the code handling Cirrus-specific hooks out of Wikibase
- moving Cirrus-specific config files, and options out
- abstracting the way different search engines could be used by Wikibase search API (e.g. turn the useCirrus option into some more generic hook that extension could use to override the engine used in search)
- do not depend on/use FieldDefintions object in Wikibase's EntityHandlers etc. I have no immediate suggestion at hand yet, looking at this for brief two minutes I see several options to consider.
- Transfer Cirrus-dependent code to WikibaseCirrusSearch extension, using Wikibase\Search\Elastic namespace (note removed Repo).
- Make a switch that turns on/off all search-related hooks & configs for both extensions. Default values on for Wikibase, off for WikibaseCirrusSearch
- This is the point where we should stop accepting any patches to Cirrus code in Wikibase, and re-sync all patches that happened since the start with WikibaseCirrusSearch.
- After testing, flip the config above to off for Wikibase, on for WikibaseCirrusSearch
- Drop the Cirrus hooks code from Wikibase
- Drop all Cirrus code from Wikibase