Skip to content

Commit efffdfc

Browse files
dbkindernashif
authored andcommitted
doc: tweak search to to understate certain docs
All docs are treated equally in the search results. The built-in search system knows to emphasize hits in titles and object names, but could use some help understating hits in non-definitive docs. In particular, hits to docs in the /boards, /samples, and /reference/kconfig docs are often not as important as hits in other docs, so let's push them later in the search result output. We can tweak the search results scoring (and thereby the order of display) via the ``html_search_scorer`` setting in ``conf.py`` along with a piece of JavaScript to adjust the result score. Fixes: #16935 Signed-off-by: David B. Kinder <[email protected]>
1 parent f1d515f commit efffdfc

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277

278278
# The name of a javascript file (relative to the configuration directory) that
279279
# implements a search results scorer. If empty, the default will be used.
280-
#html_search_scorer = 'scorer.js'
280+
html_search_scorer = 'scorer.js'
281281

282282
# Output file base name for HTML help builder.
283283
htmlhelp_basename = 'zephyrdoc'

doc/scorer.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Simple search result scoring code.
3+
*
4+
* Copyright 2007-2018 by the Sphinx team
5+
* Copyright (c) 2019, Intel
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
var Scorer = {
10+
// Implement the following function to further tweak the score for
11+
// each result The function takes a result array [filename, title,
12+
// anchor, descr, score] and returns the new score.
13+
14+
// For Zephyr search results, push display down for kconfig, boards,
15+
// and samples so "regular" docs will show up before them
16+
17+
score: function(result) {
18+
if (result[0].search("reference/kconfig/")>=0) {
19+
return -5;
20+
}
21+
else if (result[0].search("boards/")>=0) {
22+
return -5;
23+
}
24+
else if (result[0].search("samples/")>=0) {
25+
return -5;
26+
}
27+
else {
28+
return result[4];
29+
}
30+
},
31+
32+
33+
// query matches the full name of an object
34+
objNameMatch: 11,
35+
// or matches in the last dotted part of the object name
36+
objPartialMatch: 6,
37+
// Additive scores depending on the priority of the object
38+
objPrio: {0: 15, // used to be importantResults
39+
1: 5, // used to be objectResults
40+
2: -5}, // used to be unimportantResults
41+
// Used when the priority is not in the mapping.
42+
objPrioDefault: 0,
43+
44+
// query found in title
45+
title: 15,
46+
// query found in terms
47+
term: 5
48+
};

0 commit comments

Comments
 (0)