Wednesday, May 5, 2010

Solr Highlighting

I have used Lucene a few years ago when highlighting was not even feature. Now I am using Solr to perform my searches and highlighting is very much something we would like to use. At first, it was not very clear how to get it working and nor are the docs very helpful. So I've written up a short blurb on what was needed.

If you've configured your schema correctly where the fields to be highlighted must have "stored=true", then most of the work is in your constructed query. You need to add the following to your query:

  • hl=true
  • hl.fl=*
Here is an example query:

http://localhost:8989/solr/select?q=britta&hl=true&hl.fl=*

And an example response might be:

<response>
−
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">8</int>
−
<lst name="params">
<str name="q">britta</str>
<str name="hl.fl">*</str>
<str name="hl">true</str>
</lst>
</lst>
−
<result name="response" numFound="1" start="0">
−
<doc>
<str name="description">britta is awesome</str>
<str name="id">poddObject:67</str>
</doc>
</result>
−
<lst name="highlighting">
−
<lst name="poddObject:67">
−
<arr name="description">
<str><em>britta</em> is awesome</str>
</arr>
</lst>
</lst>
</response>


If it's still not working for you, here is another reference that provides additional things you should look for:
http://www.mail-archive.com/solr-user@lucene.apache.org/msg11031.html

Phil

No comments:

Post a Comment