Search code examples
apachesearchsolrhighlightsolrj

How can I highlight the search text in Apache Solr?


I am using Apache Solr for indexing and searching with SolrJ in java/GWT.

When I search for specific word or text then in the result I want to highlight that search text i.e. the search text is displayed in highlighted manner in the result... help me how can I implement this in my application....if anyone knows any solution...

Thanking in advance...


Solution

  • You can use Solr Highlight for this. By default hightlight component is enabled in solrconfig.xml. You can configure fragmenters inside the highlightComponent section in solrconfig.xml file.

    You can also set highlighting parameters inside requestHandler such as :

       <!-- Highlighting defaults -->
       <str name="hl">on</str>
       <str name="hl.fl">text features name</str>
       <str name="f.name.hl.fragsize">0</str>
       <str name="f.name.hl.alternateField">name</str>
    

    Then you can query solr as follows, which will list the highlighted keywords inside tags.

    http://localhost:8983/solr/select?q=keyword&hl=true