You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by Apache Wiki <wi...@apache.org> on 2009/09/12 19:09:18 UTC
[Solr Wiki] Trivial Update of "Solrj" by JayHill
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Solr Wiki" for change notification.
The following page has been changed by JayHill:
http://wiki.apache.org/solr/Solrj
The comment on the change is:
Added example of setting highlighting params and getting back hl results.
------------------------------------------------------------------------------
All the setter/add methods return its instance . Hence these calls can be chained
+ === Highlighting ===
+ Highlighting parameters are set like other common parameters.
+ {{{
+ 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");
+ }
+ }
+ }}}
+
= Setting the classpath =
== Ant ==