使用pysolr显示高亮内容
我有一个Solr文档,内容大致是这样的:
<response>
<result>
...
</result>
<lst name="highlighting">
<lst name="vda.a">
<arr name="illusDesc">
<str>
Four (possibly five) female <em>figures</em> huddle together in contracted postures. The two largest
</str>
</arr>
</lst>
<lst name="vda.b">
<arr name="illusDesc">
<str>
blah blah <em>figures</em> blha blah blha
</str>
</arr>
</lst>
</lst>
</response>
我该如何遍历高亮显示的元素呢?
我在一个HTML文件中有这些内容:
{% for result in results %}
<ul>
<li>Id: <a href="#">{{ result.id }}</a></li>
<li>Illustration Description: {{ result.highlighting }}</li>
</ul>
{% endfor %}
但是当然,它会打印出高亮显示下的所有文本。我想逐个遍历,打印每个返回对象的illusDesc文本。'results'是一个pySolr的结果对象。
谢谢。
1 个回答
1
results.docs
是你正在遍历的 Solr 文档的集合。results.highlighting
则包含了 Solr 的高亮信息。你可以通过文档的 ID 在 results.highlighting
中找到对应的高亮内容。比如:
results.highlighting[result['id']]['content']