Skip to content

Commit f4c3396

Browse files
committed
Add chinese search ext
1 parent 53699ff commit f4c3396

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

docs/conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# add these directories to sys.path here. If the directory is relative to the
1818
# documentation root, use os.path.abspath to make it absolute, like shown here.
1919
sys.path.insert(0, os.path.abspath('../../Lib/'))
20+
sys.path.insert(0, os.path.abspath('exts'))
2021

2122
# -- General configuration -----------------------------------------------------
2223

@@ -26,6 +27,7 @@
2627
# Add any Sphinx extension module names here, as strings. They can be extensions
2728
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
2829
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.ifconfig']
30+
extensions += ['chinese_search',]
2931

3032
# Add any paths that contain templates here, relative to this directory.
3133
templates_path = ['_templates']
@@ -93,6 +95,8 @@
9395
# a list of builtin themes.
9496
html_theme = 'nature'
9597

98+
html_search_language = 'zh_CN'
99+
96100
# Theme options are theme-specific and customize the look and feel of a theme
97101
# further. For a list of options available for each theme, see the
98102
# documentation.

docs/exts/chinese_search.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from sphinx.search import SearchLanguage
2+
import jieba
3+
4+
class SearchChinese(SearchLanguage):
5+
lang = 'zh'
6+
7+
def init(self, options):
8+
pass
9+
10+
def split(self, input):
11+
return jieba.cut_for_search(input.encode("utf8"))
12+
13+
def word_filter(self, stemmed_word):
14+
return True
15+
16+
def setup(app):
17+
import sphinx.search as search
18+
search.languages["zh_CN"] = SearchChinese

0 commit comments

Comments
 (0)