【问题标题】:display highlighting with pysolr用 pysolr 高亮显示
【发布时间】:2014-04-08 03:34:08
【问题描述】:

我有一个如下所示的 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 文本。 “结果”是一个 pySolr 结果对象。

谢谢。

【问题讨论】:

  • 你找到解决方案了吗??

标签: python html xml solr pysolr


【解决方案1】:

results.docs 包含您正在迭代的 Solr 文档。 results.highlighting 包含 Solr 突出显示。您可以通过使用文档 ID 作为 results.highlighting 中的键来访问文档的突出显示。例如:

results.highlighting[result['id']]['content']

【讨论】:

    猜你喜欢
    • 2011-12-13
    • 2011-07-06
    • 1970-01-01
    • 1970-01-01
    • 2014-04-07
    • 1970-01-01
    • 2012-05-18
    • 2016-10-22
    • 2012-04-27
    相关资源
    最近更新 更多