It's really just a matter of what you're intentions are. There are an awful
lot of highlighting params and so highlighting is very flexible and
customizable. Regarding snippets, as an example Google presents two snippets
in results, which is fairly common. I'd recommend doing a lot of
experimenting by changing the params on the query string to get what you
want, and then setting them up in SolrJ. The example I sent was intended to
be a generic starting point and mostly just to show how to set highlighting
params and how to get back a List of highlighting results.

-Jay
http://www.lucidimagination.com


On Thu, Sep 10, 2009 at 5:40 PM, Paul Tomblin <ptomb...@xcski.com> wrote:

> If I set snippets to 99999 and "mergeContinuous" to true, will I get
> the entire contents of the field with all the search terms replaced?
> I don't see what good it would be just getting one line out of the
> whole field as a snippet.
>
> On Thu, Sep 10, 2009 at 7:45 PM, 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
> >>
> >
>
>
>
> --
> http://www.linkedin.com/in/paultomblin
>

Reply via email to