python - 如何调整 Python Sphinx 以获得良好的网站搜索结果?

标签 python scipy python-sphinx

我真的很喜欢 Python-Sphinx 文档工具,但让我烦恼的一件事是我几乎无法从 sphinx 搜索框中获得正确的搜索结果:

enter image description here

所以我想知道是否有什么技巧可以让 Sphinx 搜索框获得更好的搜索性能?另外,是否有任何工具可以让我用自定义 Google 搜索替换 Sphinx 搜索框?

谢谢!

编辑:我刚刚发现Scipy搜索框自动链接到谷歌。我想知道是否有人知道他们是如何实现这一目标的?

最佳答案

Google 搜索框的集成在 Sphinx 常见问题解答部分中有描述,您需要申请一个 Google 帐户。正如预期的那样,它对我有用。也许您可能需要调整 CSS Z-Index 以避免根据您的主题按内容覆盖搜索结果。

来自:https://www.sphinx-doc.org/en/master/faq.html?highlight=google%20search

Google 搜索

要将 Sphinx 的内置搜索功能替换为 Google 搜索,请按以下步骤操作:

  1. 转到https://cse.google.com/cse/all创建 Google 搜索代码段。

  2. 复制代码片段并将其粘贴到 Sphinx 项目中的 _templates/searchbox.html:

    <div>
       <h3>{{ _('Quick search') }}</h3>
       <script>
          (function() {
             var cx = '......';
             var gcse = document.createElement('script');
             gcse.type = 'text/javascript';
             gcse.async = true;
             gcse.src = 'https://cse.google.com/cse.js?cx=' + cx;
             var s = document.getElementsByTagName('script')[0];
             s.parentNode.insertBefore(gcse, s);
          })();
       </script>
      <gcse:search></gcse:search>
    </div>
    
  3. searchbox.html 添加到 html_sidebars 配置值。

关于python - 如何调整 Python Sphinx 以获得良好的网站搜索结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35179084/

相关文章:

python - Python中2个稀疏矩阵的特殊逐行乘法

python - 在 Sphinx 中避免来自父级的文档字符串

python - ndb.TextProperty 到 ndb.StringProperty

python - 使用 Python 删除文本文件中以特定字符开头的行

python - 绘制数组中特定范围的值 Pyplot

python - python 中 qq-plot(或 probplot)的逐点置信度包络线

python - 使用 Tensorflow 2.0 进行逻辑回归?

python - 在 Python 中使用管道文件描述符时如何检查 EOF?

python - 根据类属性更 retrofit 饰器中类方法的文档字符串

python - Sphinx 中的源级转换