Skip to content

Change search "not found" links #142867

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4919,11 +4919,12 @@
});
} else if (query.error === null) {
const dlroChannel = `https://doc.rust-lang.org/${getVar("channel")}`;
const docsrsURL = `https://docs.rs/releases/search?query=${encodeURIComponent(query.userQuery)}`;

Check failure on line 4922 in src/librustdoc/html/static/js/search.js

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars

Check failure on line 4922 in src/librustdoc/html/static/js/search.js

View workflow job for this annotation

GitHub Actions / PR - aarch64-gnu-llvm-19-2

line longer than 100 chars
const duckduckgoURL = `https://duckduckgo.com/?q=${encodeURIComponent("rust " + query.userQuery)}`;

Check failure on line 4923 in src/librustdoc/html/static/js/search.js

View workflow job for this annotation

GitHub Actions / PR - mingw-check-tidy

line longer than 100 chars

Check failure on line 4923 in src/librustdoc/html/static/js/search.js

View workflow job for this annotation

GitHub Actions / PR - aarch64-gnu-llvm-19-2

line longer than 100 chars
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const duckduckgoURL = `https://duckduckgo.com/?q=${encodeURIComponent("rust " + query.userQuery)}`;
const duckduckgoURL = `https://duckduckgo.com/?q=${encodeURIComponent("rust lang " + query.userQuery)}`;

While we're here we should probably disambiguate so people don't get results about the game (this happens to me sometimes)

output.className = "search-failed" + extraClass;
output.innerHTML = "No results :(<br/>" +
"Try on <a href=\"https://duckduckgo.com/?q=" +
encodeURIComponent("rust " + query.userQuery) +
"\">DuckDuckGo</a>?<br/><br/>" +
output.innerHTML = `No results in <code>${getVar("current-crate")}</code> :(<br/>` +
`Search for <a href="${docsrsURL}">other crates</a>?<br/>` +
`Or try on <a href="${duckduckgoURL}">DuckDuckGo</a>?<br/><br/>` +
Comment on lines +4925 to +4927
Copy link
Contributor

Choose a reason for hiding this comment

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

we can apply some simple heuristics to hide this when it would be unhelpful. for example, if query.hasReturnArrow is true, we're doing type-based search, like u8 -> u16, which probably won't give much help.

"Or try looking in one of these:<ul><li>The <a " +
`href="${dlroChannel}/reference/index.html">Rust Reference</a> ` +
" for technical details about the language.</li><li><a " +
Expand Down
Loading