diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-03-17 10:55:04 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-17 10:55:04 +0900 |
commit | e6ffda38489cf341f0393ccfc02a40b570f6f404 (patch) | |
tree | b7cdd75fb676b1b4ae59c564436494989af1dc6b | |
parent | ba99fae8a06bb3243f94c17f0ea2167d865979f6 (diff) | |
parent | 4086760f6b4e91c9b4520a73e1bb71def4206b8e (diff) | |
download | sphinx-git-e6ffda38489cf341f0393ccfc02a40b570f6f404.tar.gz |
Merge pull request #7315 from tk0miya/7293_js_splitter_code
Close #7293: html search: Allow to override JavaScript splitter
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | sphinx/search/__init__.py | 16 |
2 files changed, 17 insertions, 1 deletions
@@ -89,6 +89,8 @@ Features added * #7103: linkcheck: writes all links to ``output.json`` * #7025: html search: full text search can be disabled for individual document using ``:nosearch:`` file-wide metadata +* #7293: html search: Allow to override JavaScript splitter via + ``SearchLanguage.js_splitter_code`` * #7142: html theme: Add a theme option: ``pygments_dark_style`` to switch the style of code-blocks in dark mode diff --git a/sphinx/search/__init__.py b/sphinx/search/__init__.py index aab4297a0..d9853ff06 100644 --- a/sphinx/search/__init__.py +++ b/sphinx/search/__init__.py @@ -43,6 +43,14 @@ class SearchLanguage: This is a set of stop words of the target language. Default `stopwords` is empty. This word is used for building index and embedded in JS. + .. attribute:: js_splitter_code + + Return splitter funcion of JavaScript version. The function should be + named as ``splitQuery``. And it should take a string and return list of + strings. + + .. versionadded:: 3.0 + .. attribute:: js_stemmer_code Return stemmer class of JavaScript version. This class' name should be @@ -55,6 +63,7 @@ class SearchLanguage: lang = None # type: str language_name = None # type: str stopwords = set() # type: Set[str] + js_splitter_code = None # type: str js_stemmer_rawcode = None # type: str js_stemmer_code = """ /** @@ -425,11 +434,16 @@ class IndexBuilder: self._mapping.setdefault(stemmed_word, set()).add(docname) def context_for_searchtool(self) -> Dict[str, Any]: + if self.lang.js_splitter_code: + js_splitter_code = self.lang.js_splitter_code + else: + js_splitter_code = self.js_splitter_code + return { 'search_language_stemming_code': self.lang.js_stemmer_code, 'search_language_stop_words': jsdump.dumps(sorted(self.lang.stopwords)), 'search_scorer_tool': self.js_scorer_code, - 'search_word_splitter_code': self.js_splitter_code, + 'search_word_splitter_code': js_splitter_code, } def get_js_stemmer_rawcode(self) -> str: |