Jay, it would be great if you can add this example to the Solrj wiki:

http://wiki.apache.org/solr/Solrj

On Fri, Sep 11, 2009 at 5:15 AM, Jay Hill <jayallenh...@gmail.com> wrote:

> Set up the query like this to highlight a field named "content":
>
>    SolrQuery query = new SolrQuery();
>    query.setQuery("foo");
>
>    query.setHighlight(true).setHighlightSnippets(1); //set other params as
> needed
>    query.setParam("hl.fl", "content");
>
>    QueryResponse queryResponse =getSolrServer().query(query);
>
> Then to get back the highlight results you need something like this:
>
>    Iterator<SolrDocument> iter = queryResponse.getResults();
>
>    while (iter.hasNext()) {
>      SolrDocument resultDoc = iter.next();
>
>      String content = (String) resultDoc.getFieldValue("content"));
>      String id = (String) resultDoc.getFieldValue("id"); //id is the
> uniqueKey field
>
>      if (queryResponse.getHighlighting().get(id) != null) {
>        List<String> highightSnippets =
> queryResponse.getHighlighting().get(id).get("content");
>      }
>    }
>
> Hope that gets you what you need.
>
> -Jay
> http://www.lucidimagination.com
>
> On Thu, Sep 10, 2009 at 3:19 PM, Paul Tomblin <ptomb...@xcski.com> wrote:
>
> > Can somebody point me to some sample code for using highlighting in
> > SolrJ?  I understand the highlighted versions of the field comes in a
> > separate NamedList?  How does that work?
> >
> > --
> > http://www.linkedin.com/in/paultomblin
> >
>



-- 
Regards,
Shalin Shekhar Mangar.

Reply via email to