Page MenuHomePhabricator

Make new Vector search navigate to search result URL when selecting search result using keyboard
Closed, ResolvedPublic

Description

This task proposes a possible solution for the Wikidata-specific task T317681, with implications for new Vector search in general.

Currently, navigation for search results in the new Vector search works in two different ways.

We (Wikidata developers) propose that selecting a search result using the keyboard should also navigate to the search result’s URL, as if it had been followed as a link. (However, if a search result is highlighted, but then the input field is edited further before pressing Enter, that should count as a form submission again.) By default, this would barely make a difference: both URLs point to Special:Search, which usually redirects to the page whose title exactly matches the search input. (One URL is currently missing the wprov parameter, but that could be added to the search result URL anyways – @phuedx thought the lack of wprov when middle-clicking a search result might even be a bug.)

However, this would make a big difference on Wikidata. We would configure the Wikidata search client (wgVectorSearchClient override) to directly return item page URLs, bypassing Special:Search – because searching for the label of an item will not redirect to that item: in fact, the list of search results for an item’s label doesn’t even necessarily include that item, if its label was sufficiently generic and there are too many other search results.

Event Timeline

Lucas_Werkmeister_WMDE added subscribers: Gehel, dcausse.

(Feel free to unsubscribe if I misjudged any of the CCs, my brain is a bit fried from trying to understand all this 😅)

However, this would make a big difference on Wikidata. We would configure the Wikidata search client (wgVectorSearchClient override) to directly return item page URLs, bypassing Special:Search – because searching for the label of an item will not redirect to that item: in fact, the list of search results for an item’s label doesn’t even necessarily include that item, if its label was sufficiently generic and there are too many other search results.

Can you use wgVectorSearchUrlGenerator ?

mw.config.set('wgVectorSearchUrlGenerator', { generateUrl: function () { return '42'; } } )

(needs to be loaded before the search code is loaded)

I don’t think wgVectorSearchUrlGenerator solves our problem. The URL generator is used to generate URLs in the default restSearchClient, but we’re overriding the whole wgVectorSearchClient, so we can put whatever URLs we want into the search result objects we return. The problem is that those URLs aren’t always used – when you press Enter, Codex takes great pains to not preventDefault on the event or navigate to the selected search result’s URL, but to just let the browser submit the search form, i.e. navigate to /w/index.php (the <form>’s action=) with the parameters search=abcde (the user-visible input), title=Special:Search (a hidden input), and wprov=acrw10 (another hidden input).

Thanks for explaining. This is likely an issue with Codex then. Tagging appropriately. I don't have any concerns with the modification you are provided - we could even make it configurable if needed.

Perhaps one of the existing events could be used to modify the input value? https://doc.wikimedia.org/codex/main/components/typeahead-search.html#events

Perhaps one of the existing events could be used to modify the input value? https://doc.wikimedia.org/codex/main/components/typeahead-search.html#events

Maybe, but that means that users will see the input value change for no obvious reason, and also we’re still making a roundtrip through Special:Search (and if users have the preference to redirect to exact matches disabled, they’ll see the search results instead of the item they selected, even though searching for an item ID is generally not very useful).

We could potentially fix this by updating the onSubmit() handler in CdxTypeaheadSearch to check if there is a currently highlighted item and, if so, do the following:

  • preventDefault() on the submit event
  • run the onSearchResultClick() method to emit the proper data for instrumentation
  • navigate to the highlighted item's URL
  • return

We might even be able to bypass all of this via some key modifiers on the menu item links in the template, but I haven't looked into that yet.

Would this be acceptable from the Web team's standpoint, given that the form would no longer be submitted under this circumstance, and a different event would be emitted (search-result-click instead of submit)?

I think the lack of wprov on keyboard is likely a bug. I think it's fine for these behaviours to be consistent and the conditional behaviour of onSubmit handler seems fine.
Regarding the instrumentation, tracking these as a submit event instead of a click also seems a bug, so that sounds fine to me.

tracking these as a submit event instead of a click also seems a bug

+1, thanks for weighing in!

Regarding the instrumentation, tracking these as a submit event instead of a click also seems a bug, so that sounds fine to me.

Seconded! However, it is consistent with the instrumentation for the non-Vue search treatment, e.g. when I

  1. Start a new private browsing session
  2. Navigate to en:Main_Page
  3. Run
mw.trackSubscribe( 'mediawiki.searchSuggest', ( _topic, data ) => console.log( data.action ) );

in the console

  1. Search for "Animals as Leaders"
  2. Highlight the first result and press return

I see the following in the console:

…
session-start
render-one
render-one
impression-results
submit-form

This behaviour will need to be corrected in both instruments so that the corresponding datasets are still comparable.

Hm, but the old-style search (resources/src/mediaWiki.searchSuggest/searchSuggest.js in MediaWiki core) has the same behavior of submitting the form on Enter but following the link on click. Does that mean we’re changing the behavior there as well, to always follow the link when a search result is selected?

I also notice that the old-style search generates URLs like &wprov=acrw1_0, &wprov=acrw1_1, etc., while the new search generates &wprov=acrw10, &wprov=acrw11, etc. – is the difference intentional?

Change 837133 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/skins/Vector@master] search: Add wprov to result URLs

https://gerrit.wikimedia.org/r/837133

I think the lack of wprov on keyboard is likely a bug.

I uploaded a change to fix that, as a start for working on this task. (For the rest, I’m still curious if the legacy search should also be changed to follow the URL instead of submitting the form.)

Lucas_Werkmeister_WMDE changed the task status from Open to Stalled.Oct 4 2022, 10:53 AM

Marking this task stalled for further work, at least from the WMDE side, until we’ve decided:

  • Are we changing Codex TypeaheadSearch behavior to navigate to the result’s URL on Enter, as outlined in T317682#8249254? (I assume yes, but I don’t think we’ve had a clear statement on this yet.)
  • Are we also changing MediaWiki searchSuggest behavior (“legacy search”) to do the same thing?
    • If yes, do we need to make sure that these changes roll out in the same train, to have the tracking consistent at every point in time? (I suspect yes, but it’ll increase complexity a bit further.)
  • And finally, who is responsible for doing this work? :)

Are we changing Codex TypeaheadSearch behavior to navigate to the result’s URL on Enter, as outlined in T317682#8249254? (I assume yes, but I don’t think we’ve had a clear statement on this yet.)

I think that's fine.

Are we also changing MediaWiki searchSuggest behavior (“legacy search”) to do the same thing?

I don't know who would be the right person to ask. I think legacy Vector is becoming less important as we roll out desktop improvements. I don't think the web team particularly cares. Suggest not changing it until someone asks and maybe pinging a few product analytics folks (maybe in the shared Slack channel?) ?

And finally, who is responsible for doing this work? :)

Ideally, I would like you to lead this work since you are closes to the requirements, with Design systems team (E.g. Anne) playing the neutral party. I'd be happy to provide testing/code review from the web / non-Wikidata side of things.

Are we also changing MediaWiki searchSuggest behavior (“legacy search”) to do the same thing?

I don't know who would be the right person to ask. I think legacy Vector is becoming less important as we roll out desktop improvements. I don't think the web team particularly cares. Suggest not changing it until someone asks and maybe pinging a few product analytics folks (maybe in the shared Slack channel?) ?

Definitely reach out to Product Analytics and the Search Platform teams.

At the risk of either stalling and/or increasing the scope of this task further, I would first ask those teams if there is anything using the data produced by the instrumentation and whether it should be decommissioned. For instance:

  1. There's no reference to the SearchSatisfaction legacy EventLogging schema outside of the instrument or infrastructure that supports the instrument: https://codesearch.wmcloud.org/search/?q=SearchSatisfaction; and
  2. There's just one reference to any of the instrument's provenance parameters outside of the instrument (see https://codesearch.wmcloud.org/search/?q=(srpw1%7Cacrw1%7Cdym1%7Cdymr1%7Cdymo1) ), which is in the WD/WikidataAdHocAnalytics repo

For whatever it's worth, I'm more than happy to help out in any way that I can – especially if it involves decommissioning instruments, which has become a hobby of mine recently.

There's just one reference to any of the instrument's provenance parameters outside of the instrument (see https://codesearch.wmcloud.org/search/?q=(srpw1%7Cacrw1%7Cdym1%7Cdymr1%7Cdymo1) ), which is in the WD/WikidataAdHocAnalytics repo

I looked into this, and the reference in WD/WikidataAdHocAnalytics is just a chance string match in a base64 encoded image. Complete false positive.

Are we also changing MediaWiki searchSuggest behavior (“legacy search”) to do the same thing?

I don't know who would be the right person to ask. I think legacy Vector is becoming less important as we roll out desktop improvements. I don't think the web team particularly cares. Suggest not changing it until someone asks and maybe pinging a few product analytics folks (maybe in the shared Slack channel?) ?

Definitely reach out to Product Analytics and the Search Platform teams.

@phuedx can you maybe reach out to those teams (and maybe also ask about decommissioning)? I don’t think I’m in the right Slack channels for that.

Regarding the instrumentation, tracking these as a submit event instead of a click also seems a bug, so that sounds fine to me.

Seconded! However, it is consistent with the instrumentation for the non-Vue search treatment … This behaviour will need to be corrected in both instruments so that the corresponding datasets are still comparable.

If I’m not mistaken, the “old search” side of this tracking happens in this code – that looks like we could change it to log either “click” or “submit” depending on the data.action, without actually changing the behavior (to reduce the amount of required changes). Does that sound okay?

@phuedx can you maybe reach out to those teams (and maybe also ask about decommissioning)? I don’t think I’m in the right Slack channels for that.

@mpopov confirmed that there are active uses of the SearchSuggestion data, e.g. https://github.com/wikimedia-research/search-traffic-breakdown/blob/main/dashboard/get-events.ipynb

If I’m not mistaken, the “old search” side of this tracking happens in this code – that looks like we could change it to log either “click” or “submit” depending on the data.action, without actually changing the behavior (to reduce the amount of required changes). Does that sound okay?

That sounds correct but that change would have to be coordinated with @cchen, the Data Analyst for Search Platform.

I also notice that the old-style search generates URLs like &wprov=acrw1_0, &wprov=acrw1_1, etc., while the new search generates &wprov=acrw10, &wprov=acrw11, etc. – is the difference intentional?

This is a bug and should be fixed. To be clear, we should be generating wprov parameters like acrw1_foo.

I also notice that the old-style search generates URLs like &wprov=acrw1_0, &wprov=acrw1_1, etc., while the new search generates &wprov=acrw10, &wprov=acrw11, etc. – is the difference intentional?

This is a bug and should be fixed. To be clear, we should be generating wprov parameters like acrw1_foo.

Alright, I can upload a separate fix for that. What should the value be for a search where the user didn’t select an autocomplete result? The Vue search uses acrw1 in that case (only the [slightly incorrect] prefix without an index), the old search uses acrw1_-1 (prefix plus -1 as the index).

Edit: I don’t fully understand what the old search does – when I quickly type in the search form and submit it, the request seems to be made with wprov=acrw1_-1 (prefix plus -1 as the index), but there’s also a comment in the code that sounds like it should be acrw1 (like in the Vue search)?

Poked over the history and the related tests. There are tests in tests/browser/SearchSatisfactionTests.php that expect to log a -1 as the position when the user submits their own query and not something provided by the autocomplete. This seems to have been provided as data.index to the autocomplete track function.

The specific referenced comment looks to be outdated, from the git history that looks to have been added in the first patch that implemented autocomplete handling which was further extended but the comment was not updated to match the new reality. The cameFromAutocomplete value that it sets looks to be unused.

Change 845463 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/skins/Vector@master] search: Make wprov value match non-Vue behavior

https://gerrit.wikimedia.org/r/845463

Change 837133 merged by jenkins-bot:

[mediawiki/skins/Vector@master] search: Add wprov to result URLs

https://gerrit.wikimedia.org/r/837133

Change 845463 merged by jenkins-bot:

[mediawiki/skins/Vector@master] search: Make wprov value match non-Vue behavior

https://gerrit.wikimedia.org/r/845463

Lucas_Werkmeister_WMDE changed the task status from Stalled to Open.Nov 1 2022, 9:28 AM

Unstalling because I think we can continue working on this, though we’ll need to coordinate merging / deployment with @cchen according to T317682#8332450.

Change 854049 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[design/codex@main] Treat submits with selected search result like clicks

https://gerrit.wikimedia.org/r/854049

We could potentially fix this by updating the onSubmit() handler in CdxTypeaheadSearch to check if there is a currently highlighted item and, if so, do the following:

  • preventDefault() on the submit event
  • run the onSearchResultClick() method to emit the proper data for instrumentation
  • navigate to the highlighted item's URL
  • return

We might even be able to bypass all of this via some key modifiers on the menu item links in the template, but I haven't looked into that yet.

Would this be acceptable from the Web team's standpoint, given that the form would no longer be submitted under this circumstance, and a different event would be emitted (search-result-click instead of submit)?

I implemented something along these lines in the above change.

If I’m not mistaken, the “old search” side of this tracking happens in this code – that looks like we could change it to log either “click” or “submit” depending on the data.action, without actually changing the behavior (to reduce the amount of required changes). Does that sound okay?

I think I got this the wrong way around – the searchSatisfaction.js code I linked already logs both submit-form and click-result actions as a click; there’s nothing to be changed from a submit to a click here.

If I understand @phuedx in T317682#8254889 correctly, the part that needs to change is the code that emits mediawiki.searchSuggest tracking, whereas searchSatisfaction.js is a consumer of this tracking. The emitting side is in MediaWiki core (and only there, if I’m not mistaken).

Change 854532 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] Treat search result suggestions like clicks

https://gerrit.wikimedia.org/r/854532

Uploaded a change for mediawiki.searchSuggest above; I went with actually following the URL after all, since that seemed easier to implement than submitting the form but not tracking a form submit, given how the code is arranged.

If I understand @phuedx in T317682#8254889 correctly, the part that needs to change is the code that emits mediawiki.searchSuggest tracking, whereas searchSatisfaction.js is a consumer of this tracking. The emitting side is in MediaWiki core (and only there, if I’m not mistaken).

That's correct, yes.

Change 854049 merged by jenkins-bot:

[design/codex@main] Treat submits with selected search result like clicks

https://gerrit.wikimedia.org/r/854049

With the Codex change merged (thanks!), I guess we will want to update to the next Codex release (whenever that happens) during the same train cycle where we also merge the MediaWiki core change, to keep the tracking in sync between the two kinds of search.

Do we have someone who can review that code? (Also pinging @cchen again for the tracking change.)

Change 854532 merged by jenkins-bot:

[mediawiki/core@master] Treat search result suggestions like clicks

https://gerrit.wikimedia.org/r/854532

Hm, does that mean we need a new Codex release before the branch cut on Monday now?

@Lucas_Werkmeister_WMDE our next scheduled Codex release is Tuesday, November 22nd, so it would ride the train the following week. Is that acceptable, or is this needed sooner?

I think that’s a question for @phuedx – is it okay if the tracking is out of sync for two trains?

If not, I guess we can revert the core change for now, and reapply it later. (I think this would be a case where self-merging the reapply would be allowed, since it would just be repeating an already reviewed change.)

I think that’s a question for @phuedx – is it okay if the tracking is out of sync for two trains?

If not, I guess we can revert the core change for now, and reapply it later. (I think this would be a case where self-merging the reapply would be allowed, since it would just be repeating an already reviewed change.)

I'm sorry for not thinking about this before merging your change!

I think your suggestion to revert the change and reapply it later is a good one and I agree that it's a case where self-merging applies – please do feel free to point to my review on Gerrit and/or this comment.

Change 855597 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/core@master] Treat search result suggestions like clicks (v2)

https://gerrit.wikimedia.org/r/855597

The revert is at https://gerrit.wikimedia.org/r/c/mediawiki/core/+/855596 (already merged) – I forgot to include the task ID in the commit message. The revert-revert is also uploaded (“v2” just above).

Change 859597 had a related patch set uploaded (by Anne Tomasevich; author: Anne Tomasevich):

[mediawiki/core@master] Update Codex from v0.2.2 to v0.3.0

https://gerrit.wikimedia.org/r/859597

Change 859597 merged by jenkins-bot:

[mediawiki/core@master] Update Codex from v0.2.2 to v0.3.0

https://gerrit.wikimedia.org/r/859597

@Lucas_Werkmeister_WMDE FYI we've just merged the new release of Codex into core, which includes your change and will ride the train next week!

Change 855597 merged by jenkins-bot:

[mediawiki/core@master] Treat search result suggestions like clicks (v2)

https://gerrit.wikimedia.org/r/855597

Lucas_Werkmeister_WMDE claimed this task.

Thanks! I think we can close this task – it can’t really be verified in production until we deploy proper Wikidata support in the new Vector search in general, since for regular search results there’s supposed to be no difference between following the URL and submitting the form.