As a user or editor browsing the Wikidata website, I want to quickly navigate to search results when using the main search bar on the page.
Problem:
Currently, navigation for search results in the new Vector search works in two different ways.
- If you interact with a search result as a link (left-click, middle-click, right-click + open in new tab, etc.), it sends you to the link address. With the default Vector URL generator, that link address is a Special:Search URL.
- If you highlight a search result using the arrow keys on the keyboard, and then press Enter, then the behavior is the same as if you had entered the result’s label by hand and pressed Enter afterwards: you are sent to Special:Search with the result’s label as the search text, plus a hidden input for a wprov parameter.
In both cases, Special:Search will then redirect you to the page whose title exactly matches the search text (e.g. https://en.wikipedia.org/wiki/Test), unless it’s configured to show search results even for exact matches (either by user preference or, such as on Commons, even by default: https://commons.wikimedia.org/w/?search=Leonardo+da+Vinci does not redirect to https://commons.wikimedia.org/wiki/Leonardo_da_Vinci).
The second approach doesn’t work at all for Wikidata items, where the search result’s label is not the same as the page title, or even uniquely identifies the search result: there are plenty of items labelled “Berlin”, but if I highlight the search result for Berlin, Illinois and press Enter, I want to navigate to that particular item, not a search results page for “Berlin” in general.
Example:
Currently, you can only try this out using the proof of concept from T316093; you can paste the following code into the console on Test Wikidata (not real Wikidata):
var vectorSearchClient = { fetchByTitle: ( q, domain, limit = 10, showDescription = true ) => { var api = new mw.Api(); var data = { action: 'wbsearchentities', search: q, format: 'json', errorformat: 'plaintext', language: 'en', uselang: 'en', type: 'item' } var getJson = api.get( data ); function getMatchText( { type, text } ) { if ( type === 'alias' || type === 'entityId' ) { return text; } return ''; } const searchResponsePromise = getJson.then( ( res ) => { return { query: q, results: res.search.map( ( { id, label, title, url, match, description, display = {} } ) => ( { value: id, label, match: getMatchText( match ), description, title, url, language: { label: display?.label?.language, match: match.type === 'alias' ? match.language : undefined, description: display?.description?.language }, } ) ), }; } ); return { fetch: searchResponsePromise, abort: () => { api.abort(); } }; } }; mw.config.set( 'wgVectorSearchClient', vectorSearchClient );
Otherwise, you can see the described behavior difference e.g. on English Wikipedia, if you look at the network monitor – each way of selecting a search result will eventually send you to the result page, but the Special:Search URLs in between will look slightly different depending on whether you clicked a search result or selected it using the keyboard.
Screenshots/mockups:
BDD
GIVEN I am on a wiki using the Vector 2022 skin
AND Wikibase is configured to provide custom search results for Vector 2022’s search (instead of the default title-based search)
WHEN I search for a string
AND highlight a result using the arrow keys
AND press Enter
THEN I am redirected to the item I highlighted
Acceptance criteria:
- Users can select and navigate to search results using the keyboard on Wikidata
Open questions: