Skip to content
Closed
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
8 changes: 6 additions & 2 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,14 @@ const Search = {
for (const [title, foundTitles] of Object.entries(allTitles)) {
if (title.toLowerCase().trim().includes(queryLower) && (queryLower.length >= title.length/2)) {
for (const [file, id] of foundTitles) {
let score = Math.round(100 * queryLower.length / title.length)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

100 appears to be a total magic number AFAICT

let isMainTitle = titles[file] === title
// score these a little bit above document matches, with more of a boost
// for main document titles
let baseScore = Scorer.title + (isMainTitle ? 2 : 1)
let score = Math.round(baseScore * queryLower.length / title.length)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
let score = Math.round(baseScore * queryLower.length / title.length)
let baseScore = (isMainTitle ? Scorer.title : Scorer.partialTitle) + 1

Got more relevant results by doing the above, but it feels even more hacky. Also comes at the cost of pushing subtitle matches even further down.

image

normalResults.push([
docNames[file],
titles[file] !== title ? `${titles[file]} > ${title}` : title,
isMainTitle ? title : `${titles[file]} > ${title}`,
id !== null ? "#" + id : "",
null,
score,
Expand Down