Skip to content

Commit

Permalink
html search: use a Map to collect file-term scores (#13060)
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
  • Loading branch information
jayaddison and AA-Turner authored Oct 24, 2024
1 parent 70c253e commit bd7d595
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ Features added
Bugs fixed
----------

* #13060: HTML Search: use ``Map`` to store per-file term scores.
Patch by James Addison

Testing
-------
7 changes: 4 additions & 3 deletions sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,9 @@ const Search = {

// set score for the word in each file
recordFiles.forEach((file) => {
if (!scoreMap.has(file)) scoreMap.set(file, {});
scoreMap.get(file)[word] = record.score;
if (!scoreMap.has(file)) scoreMap.set(file, new Map());
const fileScores = scoreMap.get(file);
fileScores.set(word, record.score);
});
});

Expand Down Expand Up @@ -587,7 +588,7 @@ const Search = {
break;

// select one (max) score for the file.
const score = Math.max(...wordList.map((w) => scoreMap.get(file)[w]));
const score = Math.max(...wordList.map((w) => scoreMap.get(file).get(w)));
// add result to the result list
results.push([
docNames[file],
Expand Down

0 comments on commit bd7d595

Please sign in to comment.