我试图从Solr搜索输出突出显示的搜索项。我用的是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 }}的东西,这样我就可以输出模板中突出显示的字符串了吗?
发布于 2015-10-14 15:02:04
基本上,我在视图中添加了以下代码:
for d in response:
d['highlighted_string'] = response.highlighting[d['id']]
results_list = response因此,来自solr的每个结果项都包含与其自身ID相对应的highlighted_string。然后,在模板中,result.highlighted_string输出与该结果对应的正确的highlighted_string。
我希望这能对其他人有所帮助。
https://stackoverflow.com/questions/32548581
复制相似问题