Skip to content

Author autocomplete search can fail to return useful results, improve search logic #38791

@claudiulodro

Description

@claudiulodro

Description

Under certain circumstances, the author autocomplete search can fail to return the searched-for author. This is because of the way it's implemented. It uses the REST API author search and then filters those results by author name. Since the REST API author search also searches over the user email field, on sites with a lot of users having the same email domain, those email domain-related results can fill up all of the results in the API response, and the client-side filtering of the search results will say that nothing is found. The steps to reproduce explain this better and why it's an issue.

This issue mainly affects large sites with, for example, a few hundred users with employe.name@example.com email addresses and also a catch-all Example.com user account for posting things that don't fall under any specific author. The catch-all Example.com user account will not show up in the author autocomplete search in this situation (it will display nothing when searching for Example.com).

My recommendation would be to exclude email addresses in the REST API search that the author autocomplete uses.

Step-by-step reproduction instructions

  1. Generate 500 users. (wp user generate --count=500 --role=author). Give them all an example.com email address (update wp_users set user_email = 'blah@example.com' where user_email = '';).

  2. Go to the last page of the Users list in WP Admin and edit the 500th user. Change their nickname and display name to User Example:

Screen Shot 2022-02-14 at 10 40 09 AM

Screen Shot 2022-02-14 at 10 40 30 AM

  1. Go to a post. Open the network inspector. Type in example as the author search. Observe that all of the REST API responses are generated users that have example.com in the email address, and the actual "User Example" user does not show up in the autocomplete -- in fact nothing shows up in the autocomplete, since none of the 50 users in the REST API response have Example in the name (they all have example in their email address though).

Screen Shot 2022-02-14 at 10 43 42 AM

  1. Type in user example as the author search. Observe that the result comes up nicely:

Screen Shot 2022-02-14 at 10 47 31 AM

Screenshots, screen recording, code snippet

See steps to reproduce

Environment info

Tested with WP 5.9, running the version of Gutenberg that shipped with it. Tested with a clean WP site running no additional plugins. Environment was MacBook Pro and Chrome, though that shouldn't affect this issue.

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    General InterfaceParts of the UI which don't fall neatly under other labels.[Type] EnhancementA suggestion for improvement.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions