如何在 Django Haystack 中访问/配置摘要/片段

发布于 2024-12-16 21:26:42 字数 422 浏览 0 评论 0原文

我正在努力在我的网站上设置 django-haystack,并尝试在我的搜索结果中包含片段,大致如下:

关于 Wikis
结果一的标题 ...wiki 值的特殊之处在于...我总是使用当我走路时有一个 wiki...片段值三也谈论 wiki...这是另一个片段值 关于维基

我知道有一个模板标签使用 Haystack 代码来突出显示,但它生成的片段非常有限:

  • 它们总是以查询词开头
  • ,只有一个片段值,
  • 它们不支持星号查询
  • 和其他内容?

有没有办法使用 Solr 后端生成如上所示的正确片段?

I'm working on getting django-haystack set up on my site, and am trying to have snippets in my search results roughly like so:

Title of result one about Wikis
...this special thing about wiki values is that...I always use a wiki when I walk...snippet value three talks about wikis too...and here's another snippet value
about wikis.

I know there's a template tag that uses Haystack code to do the the highlighting, but the snippets it generates are pretty limited:

  • they always start with the query word
  • there's only one snippet value
  • they don't support asterisk queries
  • and other stuff?

Is there a way to use the Solr backend to generate proper snippets as shown above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝情姑娘 2024-12-23 21:26:43

底线是 Haystack 无法真正以灵活的方式使用 Solr 突出显示。我在 IRC 上与 Haystack 的主要开发人员进行了交谈,他基本上说,如果我想要获得我正在寻找的那种突出显示,获得它的唯一方法是扩展 Haystack 使用的 Solr 后端。

我涉足了大约半天,但无法让 Haystack 识别我的自定义后端。 Haystack 有一些神奇的后端加载代码,但对我来说不起作用。

因此,我已切换到 sunburnt,它为 Solr 提供了一个更轻量级且更可扩展的包装器。我希望它会表现得更好。

Bottom line is that the Solr highlighting can't really be used by Haystack in a flexible way. I spoke to the main developer for Haystack on IRC, and he said basically, if I want to have the kind of highlighting I'm looking for, the only way to get it is to extend the Solr backend that Haystack uses.

I dabbled in that for about half a day, but couldn't get Haystack to recognize my custom back end. Haystack has some magic backend loading code that just wasn't working with me.

Consequently, I've switched over to sunburnt, which provides a lighter-weight and more extensible wrapper around Solr. I'm hoping it will fare better.

往事风中埋 2024-12-23 21:26:43
from haystack.utils import Highlighter
my_text = 'This is a sample block that would be more meaningful in real life.'
my_query = 'block meaningful'
highlight = Highlighter(my_query)
highlight.highlight(my_text) 

http://docs.haystacksearch.org/dev/highlighting.html

from haystack.utils import Highlighter
my_text = 'This is a sample block that would be more meaningful in real life.'
my_query = 'block meaningful'
highlight = Highlighter(my_query)
highlight.highlight(my_text) 

http://docs.haystacksearch.org/dev/highlighting.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文