Like most others, I use SolrJ and bind my beans with @Field annotations to
read responses from Solr.
For highlighting these properties in my bean, I always write a separate
piece - Get the list of highlights from response and then use the
Map<fieldName, List<highlights>> to put them back in my original bean.

This evening, I tried creating an @Highlight annotation and modified the
DocumentObjectBinder to understand this attribute (with a bunch of other
properties).

This is how it works:
You can annotate your beans with @Highlight as underneath.

class MyBean{
  @Field
  @Highlight
  String name;

  @Field ("solr_category_field_name")
  List<String> categories;

  @Highlight ("solr_category_field_name")
  List<String> highlightedCategories

  @Field
  float score;

  ...
}

and use QueryResponse#getBeans(MyBean.class) to achieve both - object
binding as well as highlighting.
I was wondering if this can be of help to most users or not. Can this be a
possible enhancement in DocumentObjectBinder? If yes, I can write a patch.

Cheers
Avlesh

Reply via email to