#1341 support partial search for terms/titles

A search word needs to be of length > 2 to be considered
Can be deactivated by setting ``html_search_partial_matching`` to ``False``
This commit is contained in:
Timotheus Kampik 2019-01-19 01:09:43 +01:00
parent 7e45763214
commit b1c5915850
5 changed files with 22 additions and 8 deletions

View File

@ -1300,6 +1300,13 @@ that use Sphinx's HTMLWriter class.
* ``dict`` -- the ``jieba`` dictionary path if want to use
custom dictionary.
.. confval:: html_search_partial_matching
If true, the HTML search will consider words that contain a search term of
length three or longer a match. Default: ``True``.
.. versionadded:: 2.0
.. confval:: html_search_scorer
The name of a JavaScript file (relative to the configuration directory) that

View File

@ -549,6 +549,7 @@ class StandaloneHTMLBuilder(Builder):
'show_copyright': self.config.html_show_copyright,
'show_sphinx': self.config.html_show_sphinx,
'has_source': self.config.html_copy_source,
'search_partial_matching': self.config.html_search_partial_matching,
'show_source': self.config.html_show_sourcelink,
'sourcelink_suffix': self.config.html_sourcelink_suffix,
'file_suffix': self.out_suffix,

View File

@ -141,6 +141,7 @@ class Config:
'numfig': (False, 'env', []),
'numfig_secnum_depth': (1, 'env', []),
'numfig_format': ({}, 'env', []), # will be initialized in init_numfig_format()
'html_search_partial_matching': (True, 'html', []),
'math_number_all': (False, 'env', []),
'math_eqref_format': (None, 'env', [str]),

View File

@ -7,4 +7,5 @@ var DOCUMENTATION_OPTIONS = {
HAS_SOURCE: {{ has_source|lower }},
SOURCELINK_SUFFIX: '{{ sourcelink_suffix }}',
NAVIGATION_WITH_KEYS: {{ 'true' if theme_navigation_with_keys|tobool else 'false'}},
PARTIAL_SEARCH_MATCHING: {{ 'true' if search_partial_matching|tobool else 'false'}}
};

View File

@ -36,8 +36,10 @@ if (!Scorer) {
// query found in title
title: 15,
partialTitle: 7,
// query found in terms
term: 5
term: 5,
partialTerm: 2
};
}
@ -390,15 +392,17 @@ var Search = {
{files: titleterms[word], score: Scorer.title}
];
// add support for partial matches
for (var w in terms) {
if ( w.match(word) ) {
_o.push({files: terms[w], score: Scorer.term/2})
}
}
for (var w in titleterms) {
if (DOCUMENTATION_OPTIONS.PARTIAL_SEARCH_MATCHING && word.length > 2) {
for (var w in terms) {
if (w.match(word)) {
_o.push({files: titleterms[w], score: Scorer.title/2})
_o.push({files: terms[w], score: Scorer.partialTerm})
}
}
for (var w in titleterms) {
if (w.match(word)) {
_o.push({files: titleterms[w], score: Scorer.partialTitle})
}
}
}
// no match but word was a required one