Skip to content

rustdoc search: rank aliases lower than exact matches #142653

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lolbinarycat
Copy link
Contributor

@lolbinarycat lolbinarycat commented Jun 17, 2025

will fix #140968

@rustbot rustbot added A-rustdoc-search Area: Rustdoc's search feature T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Jun 17, 2025
@rust-log-analyzer

This comment has been minimized.

@lolbinarycat lolbinarycat force-pushed the rustdoc-search-order-alias-140968 branch from 3d87e1c to cbf25eb Compare June 19, 2025 17:38
@rust-log-analyzer

This comment has been minimized.

@lolbinarycat lolbinarycat force-pushed the rustdoc-search-order-alias-140968 branch from cbf25eb to 6a8013d Compare June 19, 2025 21:20
@rust-log-analyzer

This comment has been minimized.

@lolbinarycat lolbinarycat force-pushed the rustdoc-search-order-alias-140968 branch from 6a8013d to 07f9c38 Compare June 19, 2025 23:06
@lolbinarycat lolbinarycat force-pushed the rustdoc-search-order-alias-140968 branch from 07f9c38 to f9bf376 Compare June 19, 2025 23:09
@lolbinarycat lolbinarycat marked this pull request as ready for review June 20, 2025 01:01
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

r? @GuillaumeGomez

rustbot has assigned @GuillaumeGomez.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @jsha, @lolbinarycat

Comment on lines +4336 to +4343
let exactMatches = 0;
while (
ret.others[exactMatches] !== undefined &&
ret.others[exactMatches].dist === 0 &&
ret.others[exactMatches].path_dist === 0
) {
exactMatches += 1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's the right approach: considering we plan to treat aliases the same way as all other items in the search, why not instead increase the computed distance a little (like by 0.1) to ensure it will always go after items of the same distance?

With this current code (iiuc), for each matching alias, we need to go through all results, which doesn't seem great performance wise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only have to go through all the exact matches, which there typically shouldn't only be a handful of, then the loop stops.

i initially was going to try to add alias handling before the sorting, but it turns out the sorting function is also what cleans the results, and i wasn't confident enough in our typechecking yet to translate the alias results into the correct form. I was also worried about aliases missing a bunch of fields that are used in sorting.

I think it makes sense to fix this annoying issue sooner even if it has to be redone in the future, but if you prefer I refactor aliases immediately, I can do that.

Also, there's no need to meddle with the distance, we can just sort on the presence of the alias or is_alias field.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the distance is simple and doesn't require any other change in the sorting, hence why I think it's the way to go.

And I'd prefer for things to be done all at once directly. The changes should be rather small so let's do it. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DocSearch.ALIASES does seem to store aliases in the standard rustdoc.Row format, so that's not an issue, but solving this properly is semi-blocked on #142270, as that PR gives addIntoResults an actually correct type signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose since that PR has merge conflict I could just close it and integrate its changes into this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-search Area: Rustdoc's search feature S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rustdoc search: if all else is equal, rank alias results lower
4 participants