We'll set up a TK experiment where the treatment branch conditionally redirects Special:Search visits to Special:MediaSearch.
Traffic will be capped at 0.05% of current Special:Search volume by an A/B test (1% exposure on enwiki, 50% of which will see Treatment).
This ticket is about building the redirect behaviour within these groups. Actually setting up the experiment in Growthbook and potentially additional instrumentation will be covered in a separate task.
These will only apply to logged-out users; logged in users should always continue to go to Special:Search.
If the search request matches the criteria below, we'll redirect them to Special:SemanticSearch; if not, we'll keep them at Special:Search.
In order to maintain a consistent experience, we'll only check eligibility once and store the result for the remainder of their session. Any subsequent search will result in being sent to the same search page.
Criteria for intercepting Special:Search hits and redirecting them to Special:SemanticSearch:
- user is not logged in
- user does not already have an active session in Special:Search or Special:SemanticSearch (in which case we'll want to continue to direct them to the interface they were already using before)
- the search term has gte 5 words OR contains a question word (who, what, when, where, why, how)
- the search term does not contain advanced query logic (T437487)
- the url does not contain some of the additional Special:Search filters (e.g. `&advancedSearch-current=`, `&ns<number>=`, ...)
- there is a search term present (to avoid people getting stuck on this page if they explicitly navigate back to the other search page)
-- or perhaps even better: if there is a REFERER, so they can even keep the search term and other query params in the URL (although, privacy add-ons etc could interfere?)
-- or some blend of both, to ensure users can move out of the auto-assignment as easily as possible
-- if they did explicitly move away, update the result that we've stored in the session, so their next search is also on the search page they last explicitly visited intentionally
If this all matches, users should be temporarily redirected (302) to Special:SemanticSearch with the same query params (`&search=` would be the most important one, but we do want to preserve others like `&uselang=` or `&useskin=` or whatever in case they're set)
---
To avoid redundant redirects, once we've identified that a user is eligible for Special:SemanticSearch, we'll also want to update the `search-special-page` preference (that one allows changing the search page that the typeahead widget navigates to be default).
We should be able to accomplish that with something like this:
```
$userOptionsManager = MediaWikiServices::getInstance()->getUserOptionsManager();
$userOptionsManager->setOption( $user, 'search-special-page', 'SemanticSearch' );
```
Given that we're targeting anonymous users only, this does not risk overwriting their preferences (they have none, they simply inherit the defaults (`$wgDefaultUserOptions['search-special-page']`), but by the time we've been able to check eligibility, those defaults will already have propagated into their own "preferences")
---
**Acceptance criteria**
[] Nothing here applies to logged-in users. They will always end up on Special:Search (unless they navigate to Special:SemanticSearch directly, but it will not persist)
[] Control group users: same as logged out users
[] Searches with no advanced query features are redirected to Special:SemanticSearch AND (gte 5 words OR a question word); others remain on Special:Search
[] Users who have been on Special:Search or Special:SemanticSearch before, will keep being sent to the same place for the remainder of their session
[] Users who explicitly manually navigate to either Special:Search or Special:SemanticSearch (instead of being referred there from e.g. the typeahead widget) will not be redirected away from their choice. It will also make that special page that they navigated to their new default target for the rest of their session,