Skip to content

Commit

Permalink
[search] Refactor scoring logic adjustment:
Browse files Browse the repository at this point in the history
  * Minimize diff relative to mainline codebase to ease review/historic viewing.
  * Move updated main-title score variable into a ``Scorer`` constant.
  • Loading branch information
jayaddison committed Jun 24, 2024
1 parent 0f0624e commit 5eaea64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ if (typeof Scorer === "undefined") {
objPrioDefault: 0,

// query found in title
mainTitle: 16,
title: 15,
partialTitle: 7,
// query found in terms
Expand Down Expand Up @@ -328,14 +329,10 @@ 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 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)
let score = Math.round(titles[file] !== title ? Scorer.title : Scorer.mainTitle * queryLower.length / title.length)
normalResults.push([
docNames[file],
isMainTitle ? title : `${titles[file]} > ${title}`,
titles[file] !== title ? `${titles[file]} > ${title}` : title,
id !== null ? "#" + id : "",
null,
score,
Expand Down
2 changes: 1 addition & 1 deletion tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Basic html theme search', function() {
'Main Page',
'#main-page',
null,
17,
16,
'index.rst'
]
];
Expand Down

0 comments on commit 5eaea64

Please sign in to comment.