Skip to content

Commit 66b7e89

Browse files
committed
Implement search scorer to deprioritise retro notes
1 parent 4eb6e31 commit 66b7e89

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

doc/conf.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# For the full list of built-in configuration values, see the documentation:
44
# https://www.sphinx-doc.org/en/master/usage/configuration.html
5+
import os.path
56

67
# -- Project information -----------------------------------------------------
78
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
@@ -78,6 +79,8 @@
7879
html_last_updated_fmt = ""
7980
html_show_copyright = False
8081

82+
html_search_scorer = os.path.join(os.path.dirname(__file__), "searchscorer.js")
83+
8184
spelling_lang = "en_GB"
8285
spelling_filters = ["enchant.tokenize.MentionFilter"]
8386
spelling_warning = True

doc/searchscorer.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var Scorer = {
2+
score: result => {
3+
var [docName, title, anchor, descr, score, filename] = result
4+
5+
// Deprioritize instrument details (but still include them in results)
6+
if (docName.includes("instrument_details")) {
7+
score -= 100000;
8+
}
9+
10+
// Deprioritize retrospective-notes heavily (but still include them in results)
11+
if (docName.includes("retrospective-notes")) {
12+
score -= 1000000;
13+
}
14+
15+
return score
16+
},
17+
18+
// query matches the full name of an object
19+
objNameMatch: 11,
20+
// or matches in the last dotted part of the object name
21+
objPartialMatch: 6,
22+
// Additive scores depending on the priority of the object
23+
objPrio: {
24+
0: 15,
25+
1: 5,
26+
2: -5,
27+
},
28+
// Used when the priority is not in the mapping.
29+
objPrioDefault: 0,
30+
31+
// query found in title
32+
title: 15,
33+
partialTitle: 7,
34+
35+
// query found in terms
36+
term: 5,
37+
partialTerm: 2,
38+
};

0 commit comments

Comments
 (0)