Skip to content
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

Added prefix matching in search #2375

Merged
merged 18 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

### Unreleased

### Changed

* The search in the HTML output now prioritizes prefix matches. ([#2203], [#2375])

## Version [v1.2.1] - 2023-12-02

### Fixed
Expand Down Expand Up @@ -1721,6 +1727,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2191]: https://github.com/JuliaDocs/Documenter.jl/issues/2191
[#2194]: https://github.com/JuliaDocs/Documenter.jl/issues/2194
[#2202]: https://github.com/JuliaDocs/Documenter.jl/issues/2202
[#2203]: https://github.com/JuliaDocs/Documenter.jl/issues/2203
[#2205]: https://github.com/JuliaDocs/Documenter.jl/issues/2205
[#2211]: https://github.com/JuliaDocs/Documenter.jl/issues/2211
[#2213]: https://github.com/JuliaDocs/Documenter.jl/issues/2213
Expand Down Expand Up @@ -1765,6 +1772,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#2348]: https://github.com/JuliaDocs/Documenter.jl/issues/2348
[#2364]: https://github.com/JuliaDocs/Documenter.jl/issues/2364
[#2365]: https://github.com/JuliaDocs/Documenter.jl/issues/2365
[#2375]: https://github.com/JuliaDocs/Documenter.jl/issues/2375
[JuliaLang/julia#36953]: https://github.com/JuliaLang/julia/issues/36953
[JuliaLang/julia#38054]: https://github.com/JuliaLang/julia/issues/38054
[JuliaLang/julia#39841]: https://github.com/JuliaLang/julia/issues/39841
Expand Down
7 changes: 4 additions & 3 deletions assets/html/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ let index = new minisearch({
tokenize: (string) => string.split(/[\s\-\.]+/),
// options which will be applied during the search
searchOptions: {
prefix: true,
boost: { title: 100 },
fuzzy: 2,
processTerm: (term) => {
Expand Down Expand Up @@ -322,7 +323,7 @@ function make_search_result(result, querystring) {
display_link += ` (${result.page})`;
}

let textindex = new RegExp(`\\b${querystring}\\b`, "i").exec(result.text);
let textindex = new RegExp(`${querystring}`, "i").exec(result.text);
let text =
textindex !== null
? result.text.slice(
Expand All @@ -337,8 +338,8 @@ function make_search_result(result, querystring) {
let display_result = text.length
? "..." +
text.replace(
new RegExp(`\\b${querystring}\\b`, "i"), // For first occurrence
'<span class="search-result-highlight p-1">$&</span>'
new RegExp(`${querystring}`, "i"), // For first occurrence
'<span class="search-result-highlight py-1">$&</span>'
) +
"..."
: ""; // highlights the match
Expand Down
Loading