【问题标题】:Solr highlighting through Scorched in DjangoSolr 通过 Scorched 在 Django 中突出显示
【发布时间】:2015-12-09 11:56:11
【问题描述】:

我正在尝试从 Solr 搜索中输出突出显示的搜索词。我正在使用带有 Scorched 的 Django 1.8.4。

我已经激活了突出显示(resp = ('highlighting', self.solr_response.highlighting)) 和搜索视图,我从搜索中得到的 json 输出是:

"highlighting": {

"f0109b89-4882-44cc-90b2-6a51561d14ee": { }, <!-- nothing here, though the result comes up)
"73bc1fe4-2c4a-4036-9373-242811e3e7d9": { },<!-- nothing here, though the result comes up)
"b7e7a44a-57c4-4378-94fc-273229b0ac7f":
{
"some_field":
[
    "Bla bla bla, <em>highlighted search-term</em> bla bla bla..."
]
},
)

问题是我找不到告诉 Django 模板系统访问 some_field 的方法,因为它在 content.highlighting 下(并且它的 id 在 result.id 下)。当然content.highlighting.result.id.some_field 不起作用 - 有没有办法连接类似{{ content.highlighting}} + {{ result.id }} 的东西,这样我就可以在模板中输出突出显示的字符串?

【问题讨论】:

    标签: python django solr sunburnt


    【解决方案1】:

    this is how I solved my problem.

    基本上,我在视图中添加了这段代码:

    for d in response:
        d['highlighted_string'] = response.highlighting[d['id']]
    results_list = response
    

    因此来自 solr 的每个结果项都包含与其自己的 ID 对应的 highlight_string。然后,在模板中,result.highlighted_string 输出与该结果对应的正确的 highlight_string。

    希望对其他人有帮助。

    【讨论】:

      猜你喜欢
      • 2017-10-11
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2014-12-04
      • 2013-06-13
      相关资源
      最近更新 更多