为什么不能在我的 Sphinx 中搜索到该短语?
Why the phrase can't be searched in my Sphinx?
我已经安装了 python 文档生成器-sphinx,并且 post 里面有一些文章,最近我 post 一篇名为 股票筛选器
的文章。
输入筛选
即可得到
在搜索栏中输入文章全名股票筛选器
,为什么现在搜索不到?
我已经构建了一个 sphinx 项目,用 sample.7z
压缩并上传到 dropbox,您可以下载它并将其安装到您的 sphinx 中,以重现该问题。
sample sphinx project to reproduce the issue
Sphinx 生成了一个 searchindex.js
文件。
您能否检查该文件,首先,确保您在 terms
中定义了 股票筛选器
值?
Search.setIndex({
docnames: ["docs/change-log/index", "docs/dependency-injection", "docs/examples/entity-framework"],
envversion: {
"sphinx.domains.c": 1,
"sphinx.domains.changeset": 1,
"sphinx.domains.citation": 1,
sphinx: 56
},
filenames: ["docs\change-log\index.rst", "docs\dependency-injection.rst", "docs\examples\entity-framework.rst"],
objects: {},
objnames: {},
objtypes: {},
terms: {
_dbcontext: 19,
_filepath: 19,
_logger: [0, 7, 10, 11, 14, 27],
_triggerinterv: 8,
abov: [20, 24],
kisslog: [1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 18, 19, 21, 22, 23, 24, 25],
kisslogapi: 15,
zaeffer: 24,
zero: 24
},
titles: ["Change log", "Dependency injection", "Entity Framework exceptions"],
titleterms: {
"break": 0,
Use: 6,
about: 27,
ajax: 24,
ani: 20,
antlr: 24,
}
})
这是因为 筛选
已编入索引,但 股票筛选器
未编入索引。发生这种情况是因为 股票筛选器
被识别为三个不同的 terms/words 股票
、筛选
和 器
.
索引仅存在于这些术语(忽略单个字符):
由于单个字符被忽略,只有 股票
和 筛选
会为您获取结果。
编辑
在 _static\language_data.js
中,在文件末尾附加以下代码片段:
function getAllSubstrings(str) {
var i, j, result = [];
for (i = 0; i < str.length; i++) {
for (j = i + 1; j < str.length + 1; j++) {
result.push(str.slice(i, j));
}
}
return result.sort(function(a, b){ return a.length - b.length;});
}
应该看起来像:
在 _static\searchtools.js
中插入下面的代码片段 在 上面 //console.debug('SEARCH: searching for:');
:
if(searchterms.length==1)
searchterms = getAllSubstrings(searchterms[0]);
应该看起来像:
同样,在_static\searchtools.js
函数中performTermsSearch
(这个函数应该是around/at第379行)
- 在函数内,查找此注释
// add support for
partial matches
。
- 在评论下方,你会发现这个
if
条件
word.length > 2
。
- 将条件更改为
word.length > 0
应该看起来像:
向下滚动一点。你会发现这条评论 // no match but word was a required one
.
去掉它正下方的if条件。
测试一下,应该可以工作:
我已经安装了 python 文档生成器-sphinx,并且 post 里面有一些文章,最近我 post 一篇名为 股票筛选器
的文章。
输入筛选
即可得到
在搜索栏中输入文章全名股票筛选器
,为什么现在搜索不到?
我已经构建了一个 sphinx 项目,用 sample.7z
压缩并上传到 dropbox,您可以下载它并将其安装到您的 sphinx 中,以重现该问题。
sample sphinx project to reproduce the issue
Sphinx 生成了一个 searchindex.js
文件。
您能否检查该文件,首先,确保您在 terms
中定义了 股票筛选器
值?
Search.setIndex({
docnames: ["docs/change-log/index", "docs/dependency-injection", "docs/examples/entity-framework"],
envversion: {
"sphinx.domains.c": 1,
"sphinx.domains.changeset": 1,
"sphinx.domains.citation": 1,
sphinx: 56
},
filenames: ["docs\change-log\index.rst", "docs\dependency-injection.rst", "docs\examples\entity-framework.rst"],
objects: {},
objnames: {},
objtypes: {},
terms: {
_dbcontext: 19,
_filepath: 19,
_logger: [0, 7, 10, 11, 14, 27],
_triggerinterv: 8,
abov: [20, 24],
kisslog: [1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 18, 19, 21, 22, 23, 24, 25],
kisslogapi: 15,
zaeffer: 24,
zero: 24
},
titles: ["Change log", "Dependency injection", "Entity Framework exceptions"],
titleterms: {
"break": 0,
Use: 6,
about: 27,
ajax: 24,
ani: 20,
antlr: 24,
}
})
这是因为 筛选
已编入索引,但 股票筛选器
未编入索引。发生这种情况是因为 股票筛选器
被识别为三个不同的 terms/words 股票
、筛选
和 器
.
索引仅存在于这些术语(忽略单个字符):
由于单个字符被忽略,只有 股票
和 筛选
会为您获取结果。
编辑
在 _static\language_data.js
中,在文件末尾附加以下代码片段:
function getAllSubstrings(str) {
var i, j, result = [];
for (i = 0; i < str.length; i++) {
for (j = i + 1; j < str.length + 1; j++) {
result.push(str.slice(i, j));
}
}
return result.sort(function(a, b){ return a.length - b.length;});
}
应该看起来像:
在 _static\searchtools.js
中插入下面的代码片段 在 上面 //console.debug('SEARCH: searching for:');
:
if(searchterms.length==1)
searchterms = getAllSubstrings(searchterms[0]);
应该看起来像:
同样,在_static\searchtools.js
函数中performTermsSearch
(这个函数应该是around/at第379行)
- 在函数内,查找此注释
// add support for partial matches
。 - 在评论下方,你会发现这个
if
条件word.length > 2
。 - 将条件更改为
word.length > 0
应该看起来像:
向下滚动一点。你会发现这条评论
// no match but word was a required one
.去掉它正下方的if条件。
测试一下,应该可以工作: