1

I have a solr doc that looks like this:

<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>

How do I iterate through the highlighting element?

I have this in an html file:

    {% for result in results %}
                <ul>
                    <li>Id: <a href="#">{{ result.id }}</a></li>
                    <li>Illustration Description: {{ result.highlighting }}</li>                             
                </ul>
    {% endfor %}

But of course it prints all the text under hightlighting. I want to iterate over it to print the illusDesc text for each returned object. 'results' is a pySolr Results object.

Thanks.

1 Answers1

1

results.docs contains the Solr documents you are iterating over. results.highlighting contains the Solr highlighting. You can access the highlighting for a document by using its ID as a key in results.highlighting. E.g.:

results.highlighting[result['id']]['content']
Marius Loewe
  • 236
  • 1
  • 6