From bd7d595c6b37e68acaf988e3dded04395242474b Mon Sep 17 00:00:00 2001 From: James Addison <55152140+jayaddison@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:29:56 +0000 Subject: [PATCH] html search: use a ``Map`` to collect file-term scores (#13060) Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- CHANGES.rst | 3 +++ sphinx/themes/basic/static/searchtools.js | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 6cef031159d..b47f417e9a1 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -18,5 +18,8 @@ Features added Bugs fixed ---------- +* #13060: HTML Search: use ``Map`` to store per-file term scores. + Patch by James Addison + Testing ------- diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 2c774d17aff..aaf078d2b91 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -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); }); }); @@ -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],