title: Solr function highlight for java web app
body: <p>I have search the net, but cannot seems to find the solutions on how to do Solr highlight function. I am using java eclipse jsp &amp; servlets.</p>
  
  <p><strong>F.Y.I</strong> I am using Solr 5</p>
  
  <p>My objective is when user search the words "<strong>Hello</strong>" The word hello will be <strong>highlighted</strong>.</p>
  
  <p>For example: <strong>Hello</strong> I suck at programming!</p>
  
  <p>Any expert in Solr can give me some solution? I am sure that people will down vote my question. But I got to give it a try. </p>
  
  <p>Here is the my code that I have tried. I had commented SOLR highlight in the following code how any expert in Solr can take it a look and tell me what I should do next. Also wish that some expert in Solr can share their source code if they done something like this before. </p>
  
  <pre><code>protected void doGet(HttpServletRequest request,
                  HttpServletResponse response) throws ServletException, IOException,
                  MalformedURLException {
  
              System.out.println("request parameter: "
                      + request.getParameter("search"));
              PrintWriter out = response.getWriter();
              try {
                  HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr/name/");
                  SolrQuery query = new SolrQuery();
                  String test;
                  String content;
  
                  //SOLR HIGHLIGHT
                  query.set("hl", "true");
                  query.set("hl.snippets", "1");
                  query.set("hl.simple.pre", "&lt;em&gt;");
                  query.set("hl.requireFieldMatch","true");
                  query.set("q", "value:supreme");
                  query.set("hl.fl", "id,content");
  
  
  
                  query.setQuery(request.getParameter("search"));
  
  
                  query.setFields("id");
                  query.setStart(0);
  
                  QueryResponse response1 = solr.query(query);
                  SolrDocumentList results = response1.getResults();
                  for (int i = 0; i &lt; results.size(); ++i) {
                      test = results.toString();
  </code></pre>