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:


And an example response might be:

<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>
<result name="response" numFound="1" start="0">
<str name="description">britta is awesome</str>
<str name="id">poddObject:67</str>
<lst name="highlighting">
<lst name="poddObject:67">
<arr name="description">
<str><em>britta</em> is awesome</str>

If it's still not working for you, here is another reference that provides additional things you should look for:


Tuesday, May 4, 2010

Loading configuration file from Classpath

InputStream is = getClass().getClassLoader().getResourceAsStream(INDEX_CONFIG_FILE);