In Wikibase.hooks.php, we have handlers for the ShowSearchHit and ShowSearchHitTitle hooks, as well as BeforePageDisplay hook which we use to replace the native search box with our entity selector.
this code should be split from the main hooks class, refactored and tests added.