{"id":256,"date":"2019-12-19T10:24:36","date_gmt":"2019-12-19T10:24:36","guid":{"rendered":"http:\/\/aeologic.com\/blogs\/?p=256"},"modified":"2020-03-18T08:12:11","modified_gmt":"2020-03-18T08:12:11","slug":"ultimate-solr-guide-3-highlighting-in-apache-solr","status":"publish","type":"post","link":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/","title":{"rendered":"Highlighting in Apache Solr &#8211; Ultimate Solr Guide"},"content":{"rendered":"<p>Hi folks! We are back with another post. Today we will discuss in detail an important aspect of solr which is being used by a large number of enterprise applications. It not only improves the aesthetics of the applications but also provides the end-user with a clear understanding of the response that he\/she is expecting. The feature we are discussing is called &#8220;Highlighting&#8221; in solr.<\/p>\n<p>In simple words, Highlighting in Solr allows fragments of documents that match the user\u2019s query to be included with the query response. The fragments are included in a special section of the query response (the <code>highlighting<\/code> section), and the client uses the formatting clues to determine how to present the snippets to users. Fragments are a portion of a document field that contains matches from the query and are sometimes also referred to as &#8220;snippets&#8221;.<\/p>\n<div id=\"preamble\">\n<div class=\"sectionbody\">\n<div class=\"paragraph\">\n<p>Highlighting is extremely configurable. There are many parameters each for fragment sizing, formatting, ordering, backup\/alternate behavior and more options that are hard to categorise.<\/p>\n<h3><strong>How to Use?<\/strong><\/h3>\n<div class=\"dlist\">\n<dl>\n<dt class=\"hdlist1\"><code><strong>hl<\/strong><\/code><\/dt>\n<dd>Use this parameter to enable or disable highlighting. The default is\u00a0<code>false<\/code>. If you want to use highlighting, you must set this to\u00a0<code>true<\/code>.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.method<\/code><\/strong><\/dt>\n<dd>The highlighting implementation to use. Acceptable values are:\u00a0<code>unified<\/code>,\u00a0<code>original<\/code>,\u00a0<code>fastVector<\/code>. The default is\u00a0<code>original<\/code>.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.fl<\/code><\/strong><\/dt>\n<dd>Specifies a list of fields to highlight, either comma- or space-delimited. These must be &#8220;stored&#8221;. A wildcard of\u00a0<code>*<\/code>\u00a0(asterisk) can be used to match field globs, such as\u00a0<code>text_*<\/code>\u00a0or even\u00a0<code>*<\/code> to highlight all fields where highlighting is possible. When using\u00a0<code>*<\/code>, consider adding\u00a0<code>hl.requireFieldMatch=true<\/code>. The following example uses the <a href=\"https:\/\/lucene.apache.org\/solr\/guide\/7_4\/local-parameters-in-queries.html#local-parameters-in-queries\">local-params<\/a>\u00a0syntax and\u00a0<a href=\"https:\/\/lucene.apache.org\/solr\/guide\/7_4\/the-extended-dismax-query-parser.html#the-extended-dismax-query-parser\">the edismax parser<\/a>\u00a0to highlight fields in\u00a0<code>hl.fl<\/code>:\u00a0<code>&amp;hl.fl=field1 field2&amp;hl.q={!edismax qf=$hl.fl v=$q}&amp;hl.qparser=lucene&amp;hl.requireFieldMatch=true<\/code> (along with other applicable parameters, of course).<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.q<\/code><\/strong><\/dt>\n<dd>A query to use for highlighting. This parameter allows you to highlight different terms or fields than those being used to search for documents. When setting this, you might also need to set\u00a0<code>hl.qparser<\/code>. The default is the value of the <code>q<\/code>\u00a0parameter (already parsed).<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.qparser<\/code><\/strong><\/dt>\n<dd>The\u00a0<a href=\"https:\/\/lucene.apache.org\/solr\/guide\/7_4\/query-syntax-and-parsing.html#query-syntax-and-parsing\">query parser<\/a>\u00a0to use for the\u00a0<code>hl.q<\/code>\u00a0query. It only applies when\u00a0<code>hl.q<\/code> is set. The default is the value of the <code>defType<\/code>\u00a0parameter which in turn defaults to\u00a0<code>lucene<\/code>.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.requireFieldMatch<\/code><\/strong><\/dt>\n<dd>By default,\u00a0<code>false<\/code>, all query terms will be highlighted for each field to be highlighted (<code>hl.fl<\/code>) no matter what fields the parsed query refers to. If set to <code>true<\/code>, only query terms aligning with the field being highlighted will, in turn, be highlighted.<\/p>\n<div class=\"paragraph\">\n<p>If the query references field different from the field being highlighted and they have different text analysis, the query may not highlight query terms it should have and vice versa. The analysis used is that of the field being highlighted (<code>hl.fl<\/code>), not the query fields.<\/p>\n<\/div>\n<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.usePhraseHighlighter<\/code><\/strong><\/dt>\n<dd>If set to\u00a0<code>true<\/code>, the default, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately \u2013 as phrases. If\u00a0<code>false<\/code>, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.highlightMultiTerm<\/code><\/strong><\/dt>\n<dd>If set to\u00a0<code>true<\/code>, the default, Solr will highlight wildcard queries (and other\u00a0<code>MultiTermQuery<\/code>\u00a0subclasses). If\u00a0<code>false<\/code>, they won\u2019t be highlighted at all.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.snippets<\/code><\/strong><\/dt>\n<dd>Specifies the maximum number of highlighted snippets to generate per field. It is possible for any number of snippets from zero to this value to be generated. The default is <code>1<\/code>.<\/dd>\n<dt class=\"hdlist1\"><strong><code>hl.fragsize<\/code><\/strong><\/dt>\n<dd>Specifies the approximate size, in characters, of fragments to consider for highlighting. The default is\u00a0<code>100<\/code>. Using\u00a0<code>0<\/code> indicates that no fragmenting should be considered and the whole field value should be used.<\/dd>\n<\/dl>\n<h3><strong>Highlighting in a query response<\/strong><\/h3>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"sect1\">\n<div class=\"paragraph\">\n<p>In response to a query, Solr includes highlighting data in a section separate from the documents. It is up to a client to determine how to process this response and display the highlights to users.<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>Using the example documents included with Solr, we can see how this might work:<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>In response to a query such as:<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-268\" src=\"http:\/\/aeologic.com\/blogs\/wp-content\/uploads\/2019\/12\/carbon-1.png\" alt=\"\" width=\"1902\" height=\"410\" srcset=\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1.png 889w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-720x156.png 720w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-260x56.png 260w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-370x80.png 370w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-250x54.png 250w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-300x65.png 300w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-1-768x166.png 768w\" sizes=\"(max-width: 1902px) 100vw, 1902px\" \/><\/p>\n<p>We get a response such as :<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-270\" src=\"http:\/\/aeologic.com\/blogs\/wp-content\/uploads\/2019\/12\/carbon-3.png\" alt=\"\" width=\"1396\" height=\"1166\" srcset=\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-3.png 359w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-3-260x217.png 260w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-3-96x80.png 96w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-3-227x190.png 227w, https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/carbon-3-300x251.png 300w\" sizes=\"(max-width: 1396px) 100vw, 1396px\" \/><\/p>\n<div class=\"paragraph\">\n<p>Note the two sections\u00a0<code>docs<\/code>\u00a0and\u00a0<code>highlighting<\/code>. The\u00a0<code>docs<\/code>\u00a0section contains the fields of the document requested with the\u00a0<code>fl<\/code>\u00a0parameter of the query (only &#8220;id&#8221;, &#8220;name&#8221;, &#8220;manu&#8221;, and &#8220;cat&#8221;).<\/p>\n<\/div>\n<div class=\"paragraph\">\n<p>The\u00a0<code>highlighting<\/code> section includes the ID of each document and the field that contains the highlighted portion. In this example, we used the\u00a0<code>hl.fl<\/code>\u00a0parameter to say we wanted query terms highlighted in the &#8220;manu&#8221; field. When there is a match to the query term in that field, it will be included for each document ID in the list.<\/p>\n<p>So, this is it about Highlighting in solr. We will be back with another post on solr very soon.<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Hi folks! We are back with another post. Today we will discuss in detail an important aspect of solr which is being used by a large number of enterprise applications. It not only improves the aesthetics of the applications but also provides the end-user with a clear understanding of the response that he\/she is expecting. The feature we are discussing is called &#8220;Highlighting&#8221; in solr. In simple words, Highlighting in Solr allows fragments of documents that match the user\u2019s query to be included with the query response. The fragments are included in a special section of the query response (the highlighting section), and the client uses the formatting clues to determine how to present the snippets to users. Fragments are a portion of a document field that contains matches from the query and are sometimes also referred to as &#8220;snippets&#8221;. Highlighting is extremely configurable. There are many parameters each for fragment sizing, formatting, ordering, backup\/alternate behavior and more options that are hard to categorise. How to Use? hl Use this parameter to enable or disable highlighting. The default is\u00a0false. If you want to use highlighting, you must set this to\u00a0true. hl.method The highlighting implementation to use. Acceptable values are:\u00a0unified,\u00a0original,\u00a0fastVector. The default is\u00a0original. hl.fl Specifies a list of fields to highlight, either comma- or space-delimited. These must be &#8220;stored&#8221;. A wildcard of\u00a0*\u00a0(asterisk) can be used to match field globs, such as\u00a0text_*\u00a0or even\u00a0* to highlight all fields where highlighting is possible. When using\u00a0*, consider adding\u00a0hl.requireFieldMatch=true. The following example uses the local-params\u00a0syntax and\u00a0the edismax parser\u00a0to highlight fields in\u00a0hl.fl:\u00a0&amp;hl.fl=field1 field2&amp;hl.q={!edismax qf=$hl.fl v=$q}&amp;hl.qparser=lucene&amp;hl.requireFieldMatch=true (along with other applicable parameters, of course). hl.q A query to use for highlighting. This parameter allows you to highlight different terms or fields than those being used to search for documents. When setting this, you might also need to set\u00a0hl.qparser. The default is the value of the q\u00a0parameter (already parsed). hl.qparser The\u00a0query parser\u00a0to use for the\u00a0hl.q\u00a0query. It only applies when\u00a0hl.q is set. The default is the value of the defType\u00a0parameter which in turn defaults to\u00a0lucene. hl.requireFieldMatch By default,\u00a0false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refers to. If set to true, only query terms aligning with the field being highlighted will, in turn, be highlighted. If the query references field different from the field being highlighted and they have different text analysis, the query may not highlight query terms it should have and vice versa. The analysis used is that of the field being highlighted (hl.fl), not the query fields. hl.usePhraseHighlighter If set to\u00a0true, the default, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately \u2013 as phrases. If\u00a0false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase. hl.highlightMultiTerm If set to\u00a0true, the default, Solr will highlight wildcard queries (and other\u00a0MultiTermQuery\u00a0subclasses). If\u00a0false, they won\u2019t be highlighted at all. hl.snippets Specifies the maximum number of highlighted snippets to generate per field. It is possible for any number of snippets from zero to this value to be generated. The default is 1. hl.fragsize Specifies the approximate size, in characters, of fragments to consider for highlighting. The default is\u00a0100. Using\u00a00 indicates that no fragmenting should be considered and the whole field value should be used. Highlighting in a query response In response to a query, Solr includes highlighting data in a section separate from the documents. It is up to a client to determine how to process this response and display the highlights to users. Using the example documents included with Solr, we can see how this might work: In response to a query such as: We get a response such as : Note the two sections\u00a0docs\u00a0and\u00a0highlighting. The\u00a0docs\u00a0section contains the fields of the document requested with the\u00a0fl\u00a0parameter of the query (only &#8220;id&#8221;, &#8220;name&#8221;, &#8220;manu&#8221;, and &#8220;cat&#8221;). The\u00a0highlighting section includes the ID of each document and the field that contains the highlighted portion. In this example, we used the\u00a0hl.fl\u00a0parameter to say we wanted query terms highlighted in the &#8220;manu&#8221; field. When there is a match to the query term in that field, it will be included for each document ID in the list. So, this is it about Highlighting in solr. We will be back with another post on solr very soon.<\/p>\n","protected":false},"author":3,"featured_media":383,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[41],"tags":[14,45,51,46,47,48,49,50,7],"class_list":["post-256","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-solr","tag-apache-solr","tag-enterprise-search","tag-highlighting","tag-lucene","tag-master","tag-performance","tag-performance-tips","tag-slave","tag-solr"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog\" \/>\n<meta property=\"og:description\" content=\"Hi folks! We are back with another post. Today we will discuss in detail an important aspect of solr which is being used by a large number of enterprise applications. It not only improves the aesthetics of the applications but also provides the end-user with a clear understanding of the response that he\/she is expecting. The feature we are discussing is called &#8220;Highlighting&#8221; in solr. In simple words, Highlighting in Solr allows fragments of documents that match the user\u2019s query to be included with the query response. The fragments are included in a special section of the query response (the highlighting section), and the client uses the formatting clues to determine how to present the snippets to users. Fragments are a portion of a document field that contains matches from the query and are sometimes also referred to as &#8220;snippets&#8221;. Highlighting is extremely configurable. There are many parameters each for fragment sizing, formatting, ordering, backup\/alternate behavior and more options that are hard to categorise. How to Use? hl Use this parameter to enable or disable highlighting. The default is\u00a0false. If you want to use highlighting, you must set this to\u00a0true. hl.method The highlighting implementation to use. Acceptable values are:\u00a0unified,\u00a0original,\u00a0fastVector. The default is\u00a0original. hl.fl Specifies a list of fields to highlight, either comma- or space-delimited. These must be &#8220;stored&#8221;. A wildcard of\u00a0*\u00a0(asterisk) can be used to match field globs, such as\u00a0text_*\u00a0or even\u00a0* to highlight all fields where highlighting is possible. When using\u00a0*, consider adding\u00a0hl.requireFieldMatch=true. The following example uses the local-params\u00a0syntax and\u00a0the edismax parser\u00a0to highlight fields in\u00a0hl.fl:\u00a0&amp;hl.fl=field1 field2&amp;hl.q={!edismax qf=$hl.fl v=$q}&amp;hl.qparser=lucene&amp;hl.requireFieldMatch=true (along with other applicable parameters, of course). hl.q A query to use for highlighting. This parameter allows you to highlight different terms or fields than those being used to search for documents. When setting this, you might also need to set\u00a0hl.qparser. The default is the value of the q\u00a0parameter (already parsed). hl.qparser The\u00a0query parser\u00a0to use for the\u00a0hl.q\u00a0query. It only applies when\u00a0hl.q is set. The default is the value of the defType\u00a0parameter which in turn defaults to\u00a0lucene. hl.requireFieldMatch By default,\u00a0false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refers to. If set to true, only query terms aligning with the field being highlighted will, in turn, be highlighted. If the query references field different from the field being highlighted and they have different text analysis, the query may not highlight query terms it should have and vice versa. The analysis used is that of the field being highlighted (hl.fl), not the query fields. hl.usePhraseHighlighter If set to\u00a0true, the default, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately \u2013 as phrases. If\u00a0false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase. hl.highlightMultiTerm If set to\u00a0true, the default, Solr will highlight wildcard queries (and other\u00a0MultiTermQuery\u00a0subclasses). If\u00a0false, they won\u2019t be highlighted at all. hl.snippets Specifies the maximum number of highlighted snippets to generate per field. It is possible for any number of snippets from zero to this value to be generated. The default is 1. hl.fragsize Specifies the approximate size, in characters, of fragments to consider for highlighting. The default is\u00a0100. Using\u00a00 indicates that no fragmenting should be considered and the whole field value should be used. Highlighting in a query response In response to a query, Solr includes highlighting data in a section separate from the documents. It is up to a client to determine how to process this response and display the highlights to users. Using the example documents included with Solr, we can see how this might work: In response to a query such as: We get a response such as : Note the two sections\u00a0docs\u00a0and\u00a0highlighting. The\u00a0docs\u00a0section contains the fields of the document requested with the\u00a0fl\u00a0parameter of the query (only &#8220;id&#8221;, &#8220;name&#8221;, &#8220;manu&#8221;, and &#8220;cat&#8221;). The\u00a0highlighting section includes the ID of each document and the field that contains the highlighted portion. In this example, we used the\u00a0hl.fl\u00a0parameter to say we wanted query terms highlighted in the &#8220;manu&#8221; field. When there is a match to the query term in that field, it will be included for each document ID in the list. So, this is it about Highlighting in solr. We will be back with another post on solr very soon.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\" \/>\n<meta property=\"og:site_name\" content=\"Aeologic Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/AeoLogicTech\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-19T10:24:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-18T08:12:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png\" \/>\n\t<meta property=\"og:image:width\" content=\"521\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Manoj Kumar\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@aeologictech\" \/>\n<meta name=\"twitter:site\" content=\"@aeologictech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Manoj Kumar\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\"},\"author\":{\"name\":\"Manoj Kumar\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/13549984ba8e5f441cc733ed20d7daa4\"},\"headline\":\"Highlighting in Apache Solr &#8211; Ultimate Solr Guide\",\"datePublished\":\"2019-12-19T10:24:36+00:00\",\"dateModified\":\"2020-03-18T08:12:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\"},\"wordCount\":716,\"publisher\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png\",\"keywords\":[\"apache solr\",\"enterprise search\",\"Highlighting\",\"lucene\",\"master\",\"performance\",\"performance tips\",\"slave\",\"solr\"],\"articleSection\":[\"Solr\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\",\"url\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\",\"name\":\"Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png\",\"datePublished\":\"2019-12-19T10:24:36+00:00\",\"dateModified\":\"2020-03-18T08:12:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage\",\"url\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png\",\"contentUrl\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png\",\"width\":521,\"height\":300},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.aeologic.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Highlighting in Apache Solr &#8211; Ultimate Solr Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#website\",\"url\":\"https:\/\/www.aeologic.com\/blog\/\",\"name\":\"Aeologic Blog\",\"description\":\"Aeologic\",\"publisher\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.aeologic.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#organization\",\"name\":\"AeoLogic Technologies\",\"url\":\"https:\/\/www.aeologic.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2022\/05\/new-logo-aeo.jpg\",\"contentUrl\":\"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2022\/05\/new-logo-aeo.jpg\",\"width\":385,\"height\":162,\"caption\":\"AeoLogic Technologies\"},\"image\":{\"@id\":\"https:\/\/www.aeologic.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/AeoLogicTech\/\",\"https:\/\/x.com\/aeologictech\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/13549984ba8e5f441cc733ed20d7daa4\",\"name\":\"Manoj Kumar\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/24ce77602da5eb5715d74a95733f6c7548e2af73f5a493f9bc0bf55f611d025e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/24ce77602da5eb5715d74a95733f6c7548e2af73f5a493f9bc0bf55f611d025e?s=96&d=mm&r=g\",\"caption\":\"Manoj Kumar\"},\"description\":\"Manoj Kumar is a seasoned Digital Marketing Manager and passionate Tech Blogger with deep expertise in SEO, AI trends, and emerging digital technologies. He writes about innovative solutions that drive growth and transformation across industry. Featured on - YOURSTORY | TECHSLING | ELEARNINGINDUSTRY | DATASCIENCECENTRAL | TIMESOFINDIA | MEDIUM | DATAFLOQ\",\"sameAs\":[\"https:\/\/www.aeologic.com\/\",\"https:\/\/www.linkedin.com\/in\/manoj-kumar-rajput\/\"],\"url\":\"https:\/\/www.aeologic.com\/blog\/author\/manoj\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/","og_locale":"en_US","og_type":"article","og_title":"Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog","og_description":"Hi folks! We are back with another post. Today we will discuss in detail an important aspect of solr which is being used by a large number of enterprise applications. It not only improves the aesthetics of the applications but also provides the end-user with a clear understanding of the response that he\/she is expecting. The feature we are discussing is called &#8220;Highlighting&#8221; in solr. In simple words, Highlighting in Solr allows fragments of documents that match the user\u2019s query to be included with the query response. The fragments are included in a special section of the query response (the highlighting section), and the client uses the formatting clues to determine how to present the snippets to users. Fragments are a portion of a document field that contains matches from the query and are sometimes also referred to as &#8220;snippets&#8221;. Highlighting is extremely configurable. There are many parameters each for fragment sizing, formatting, ordering, backup\/alternate behavior and more options that are hard to categorise. How to Use? hl Use this parameter to enable or disable highlighting. The default is\u00a0false. If you want to use highlighting, you must set this to\u00a0true. hl.method The highlighting implementation to use. Acceptable values are:\u00a0unified,\u00a0original,\u00a0fastVector. The default is\u00a0original. hl.fl Specifies a list of fields to highlight, either comma- or space-delimited. These must be &#8220;stored&#8221;. A wildcard of\u00a0*\u00a0(asterisk) can be used to match field globs, such as\u00a0text_*\u00a0or even\u00a0* to highlight all fields where highlighting is possible. When using\u00a0*, consider adding\u00a0hl.requireFieldMatch=true. The following example uses the local-params\u00a0syntax and\u00a0the edismax parser\u00a0to highlight fields in\u00a0hl.fl:\u00a0&amp;hl.fl=field1 field2&amp;hl.q={!edismax qf=$hl.fl v=$q}&amp;hl.qparser=lucene&amp;hl.requireFieldMatch=true (along with other applicable parameters, of course). hl.q A query to use for highlighting. This parameter allows you to highlight different terms or fields than those being used to search for documents. When setting this, you might also need to set\u00a0hl.qparser. The default is the value of the q\u00a0parameter (already parsed). hl.qparser The\u00a0query parser\u00a0to use for the\u00a0hl.q\u00a0query. It only applies when\u00a0hl.q is set. The default is the value of the defType\u00a0parameter which in turn defaults to\u00a0lucene. hl.requireFieldMatch By default,\u00a0false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refers to. If set to true, only query terms aligning with the field being highlighted will, in turn, be highlighted. If the query references field different from the field being highlighted and they have different text analysis, the query may not highlight query terms it should have and vice versa. The analysis used is that of the field being highlighted (hl.fl), not the query fields. hl.usePhraseHighlighter If set to\u00a0true, the default, Solr will highlight phrase queries (and other advanced position-sensitive queries) accurately \u2013 as phrases. If\u00a0false, the parts of the phrase will be highlighted everywhere instead of only when it forms the given phrase. hl.highlightMultiTerm If set to\u00a0true, the default, Solr will highlight wildcard queries (and other\u00a0MultiTermQuery\u00a0subclasses). If\u00a0false, they won\u2019t be highlighted at all. hl.snippets Specifies the maximum number of highlighted snippets to generate per field. It is possible for any number of snippets from zero to this value to be generated. The default is 1. hl.fragsize Specifies the approximate size, in characters, of fragments to consider for highlighting. The default is\u00a0100. Using\u00a00 indicates that no fragmenting should be considered and the whole field value should be used. Highlighting in a query response In response to a query, Solr includes highlighting data in a section separate from the documents. It is up to a client to determine how to process this response and display the highlights to users. Using the example documents included with Solr, we can see how this might work: In response to a query such as: We get a response such as : Note the two sections\u00a0docs\u00a0and\u00a0highlighting. The\u00a0docs\u00a0section contains the fields of the document requested with the\u00a0fl\u00a0parameter of the query (only &#8220;id&#8221;, &#8220;name&#8221;, &#8220;manu&#8221;, and &#8220;cat&#8221;). The\u00a0highlighting section includes the ID of each document and the field that contains the highlighted portion. In this example, we used the\u00a0hl.fl\u00a0parameter to say we wanted query terms highlighted in the &#8220;manu&#8221; field. When there is a match to the query term in that field, it will be included for each document ID in the list. So, this is it about Highlighting in solr. We will be back with another post on solr very soon.","og_url":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/","og_site_name":"Aeologic Blog","article_publisher":"https:\/\/www.facebook.com\/AeoLogicTech\/","article_published_time":"2019-12-19T10:24:36+00:00","article_modified_time":"2020-03-18T08:12:11+00:00","og_image":[{"width":521,"height":300,"url":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png","type":"image\/png"}],"author":"Manoj Kumar","twitter_card":"summary_large_image","twitter_creator":"@aeologictech","twitter_site":"@aeologictech","twitter_misc":{"Written by":"Manoj Kumar","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#article","isPartOf":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/"},"author":{"name":"Manoj Kumar","@id":"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/13549984ba8e5f441cc733ed20d7daa4"},"headline":"Highlighting in Apache Solr &#8211; Ultimate Solr Guide","datePublished":"2019-12-19T10:24:36+00:00","dateModified":"2020-03-18T08:12:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/"},"wordCount":716,"publisher":{"@id":"https:\/\/www.aeologic.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage"},"thumbnailUrl":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png","keywords":["apache solr","enterprise search","Highlighting","lucene","master","performance","performance tips","slave","solr"],"articleSection":["Solr"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/","url":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/","name":"Highlighting in Apache Solr - Ultimate Solr Guide - Aeologic Blog","isPartOf":{"@id":"https:\/\/www.aeologic.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage"},"image":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage"},"thumbnailUrl":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png","datePublished":"2019-12-19T10:24:36+00:00","dateModified":"2020-03-18T08:12:11+00:00","breadcrumb":{"@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#primaryimage","url":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png","contentUrl":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2019\/12\/highlighting-in-solr.png","width":521,"height":300},{"@type":"BreadcrumbList","@id":"https:\/\/www.aeologic.com\/blog\/ultimate-solr-guide-3-highlighting-in-apache-solr\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.aeologic.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Highlighting in Apache Solr &#8211; Ultimate Solr Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.aeologic.com\/blog\/#website","url":"https:\/\/www.aeologic.com\/blog\/","name":"Aeologic Blog","description":"Aeologic","publisher":{"@id":"https:\/\/www.aeologic.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.aeologic.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.aeologic.com\/blog\/#organization","name":"AeoLogic Technologies","url":"https:\/\/www.aeologic.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.aeologic.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2022\/05\/new-logo-aeo.jpg","contentUrl":"https:\/\/www.aeologic.com\/blog\/wp-content\/uploads\/2022\/05\/new-logo-aeo.jpg","width":385,"height":162,"caption":"AeoLogic Technologies"},"image":{"@id":"https:\/\/www.aeologic.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/AeoLogicTech\/","https:\/\/x.com\/aeologictech"]},{"@type":"Person","@id":"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/13549984ba8e5f441cc733ed20d7daa4","name":"Manoj Kumar","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.aeologic.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/24ce77602da5eb5715d74a95733f6c7548e2af73f5a493f9bc0bf55f611d025e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/24ce77602da5eb5715d74a95733f6c7548e2af73f5a493f9bc0bf55f611d025e?s=96&d=mm&r=g","caption":"Manoj Kumar"},"description":"Manoj Kumar is a seasoned Digital Marketing Manager and passionate Tech Blogger with deep expertise in SEO, AI trends, and emerging digital technologies. He writes about innovative solutions that drive growth and transformation across industry. Featured on - YOURSTORY | TECHSLING | ELEARNINGINDUSTRY | DATASCIENCECENTRAL | TIMESOFINDIA | MEDIUM | DATAFLOQ","sameAs":["https:\/\/www.aeologic.com\/","https:\/\/www.linkedin.com\/in\/manoj-kumar-rajput\/"],"url":"https:\/\/www.aeologic.com\/blog\/author\/manoj\/"}]}},"_links":{"self":[{"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/posts\/256","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/comments?post=256"}],"version-history":[{"count":0,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/posts\/256\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/media\/383"}],"wp:attachment":[{"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/media?parent=256"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/categories?post=256"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aeologic.com\/blog\/wp-json\/wp\/v2\/tags?post=256"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}