如何调整Python Sphinx以便我可以获得精美的网站搜索结果?

时间:2016-02-03 13:58:11

标签: python scipy python-sphinx

我非常喜欢Python-Sphinx文档工具,但有一件事让我感到恼火的是,我几乎无法从狮身人面像搜索框中获得正确的搜索结果:

enter image description here

所以我想知道是否有任何技巧可以让我从Sphinx搜索框中获得更好的搜索性能?此外,是否有任何工具允许我用自定义谷歌搜索替换Sphinx搜索框?

谢谢!

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

2 个答案:

答案 0 :(得分:1)

Sphinx搜索功能目前不是非常强大/可配置。

要解决您的问题,您可以

1)实施自己的Sphinx搜索或

2)调整您的Sphinx模板以支持自定义Google搜索。

对于1),您可能需要查看非稳定 Sphinx扩展程序sphinxcontrib-lunrsearch 0.2

对于2),请阅读Sphinx templating documentation

Sphinx project on GitHub中存在一些未解决的问题,因此您可以尝试回馈项目并获得Sphinx社区的支持。

答案 1 :(得分:1)

Sphinx常见问题解答部分中介绍了Google Searchbox的集成,您需要申请一个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. 复制代码段并将其粘贴到 _templates/searchbox.html在您的Sphinx项目中:

    <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配置值中。