python - 如何在Sphinx生成的文档中查找汉字和短词?

标签 python python-sphinx restructuredtext

apt-get install  python-sphinx    
apt-get install  sphinxsearch    
mkdir rest    
cd rest/    
sphinx-quickstart    

我在重组文本中创建了我的第一篇文章。
http://s.yunio.com/!LrAsu

请下载并在您的计算机上解压,cd 到 /rest/build/html,用您的 chrome 打开 index.rst。

我发现在重构的文本搜索功能中:

1.无法搜索汉字
2.不能搜索短词

请看附件1,这是我要搜索的目标文章
enter image description here 你可以在文本中看到标准

请看附件2,不能搜索正文中的汉字标准enter image description here 请看附件3,不能搜索正文中的短词isenter image description here

我该如何解决这个问题?

最佳答案

编辑:

Sphinx 只为整个中文句子建立索引,因为其中没有空格,Sphinx 不知道在哪里拆分单词来建立索引。检查文件 searchindex.js 以获取生成的索引。

尝试搜索“标准表示方式”这个词,它有效。 ^_^

Sphinx 使用 python 脚本 search.py​​ 构建索引。深入研究可以发现

stopwords = set("""
a  and  are  as  at
be  but  by
for
if  in  into  is  it
near  no  not
of  on  or
such
that  the  their  then  there  these  they  this  to
was  will  with
""".split())

这就是为什么找不到短词的原因。如果您只想让这些词出现在索引中,您可以从此列表中删除这些词。

我们还可以找到这一行:

word_re = re.compile(r'\w+(?u)')

这是 Sphinx 用来分割单词的正则表达式。现在我们可以明白为什么它不能索引中文单词了。

解决方案是在这个文件中添加中文分词支持。已经有人做了:http://hyry.dip.jp/tech/blog/index.html?id=374

Sphinx 搜索引擎的答案:

我把它留在这里以防其他人发现它有用。感谢mzjn指出。

Sphinx 默认不支持中文,因为它无法识别中文字符集。它不知道在哪里拆分单词来建立索引。需要修改配置文件让它对中文词进行索引。

更具体地说,您应该修改 sphinx.conf 中的 charset_tablengram_lenngram_chars 以使其工作.您可以用谷歌搜索这些关键字以获得正确的配置。

但是,Sphinx 可能会生成一个巨大的索引,因为每个汉字都被视为一个单词。所以试试coreseek相反,如果你真的想为中文文档建立索引。

关于python - 如何在Sphinx生成的文档中查找汉字和短词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16745193/

相关文章:

python - xml.etree.ElementTree - 设置 xmlns = '...' 时遇到问题

python - 如何获取类中的所有属性?

python - 快速开发路由协议(protocol)原型(prototype)的环境

localization - 如何本地化 reStructuredText 和 Sphinx 消息?

python-sphinx - 在 Sphinx 文档中使用全局变量标准化链接

python-sphinx - Sphinx 的 "only"和 "ifconfig"指令有什么区别?

python-sphinx - 在 reStructuredText 中跳过标题级别

python - 两个相同值的差不为零

Python Sphinx autodoc 和装饰成员

python-sphinx - 如何使用 reStructuredText 在超链接目标中包含空格?