-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
lolbinarycat
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
lolbinarycat:rustdoc-search-order-alias-140968
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// rank doc aliases lower than exact matches | ||
// regression test for <https://github.com/rust-lang/rust/issues/140968> | ||
|
||
const EXPECTED = { | ||
'query': 'foobazbar', | ||
'others': [ | ||
{ 'name': 'foobazbar' }, | ||
{ 'name': 'foo' }, | ||
], | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// asdf | ||
pub fn foobazbar() {} | ||
|
||
#[doc(alias("foobazbar"))] | ||
pub fn foo() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// ignore-order | ||
|
||
const PARSED = [ | ||
{ | ||
query: '中文', | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this comment.
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 standardrustdoc.Row
format, so that's not an issue, but solving this properly is semi-blocked on #142270, as that PR givesaddIntoResults
an actually correct type signature.There was a problem hiding this comment.
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.