I am working to enable Standard Highlighting on my server with Solr 4.7. My documents contain (among the others) the following fields:
{
"id": [
"fdc3833a-0e4f-4314-ba8c"
],,
"tag": [
"solr",
"solrJ",
"solrCloud"
"solrX"
],
"title": "Solr question about highlighting",
"description": "I am working to enable Standard Highlighting on my server with Solr 4.7. My documents contain (among the others) the following.........",
}
Out of the three fields, only "tag" is multivalue. My default configuration within solrconfig.xml file is:
<str name="hl">on</str>
<str name="hl.fl">content title description tag</str>
<str name="hl.snippets">2</str>
When I run a query like:
https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true
I get the following highlights:
"highlighting": {
"fdc3833a-0e4f-4314-ba8c": {
"title": [
"<b>Solr</b> question about highlighting"
],
"summary": [
"I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
],
**"tag": [
"<b>Solr</b>",
"<b>SolrJ</b>"
]**
}
}
While I would expect to get all the tags. I discovered that Solr treats multiple values in a multivalued fields as they were highlighted snippets, so since I have hl.snippets=2 only the first two values are displayed. How can I get all the values for tags? (obviously changing the number of snippets just for the multivalue fields is not an acceptable answer). Is there a way in Solr 4.7 to deal with multivalue fields in highlighting?
My expectations would be to have a response like:
"highlighting": {
"fdc3833a-0e4f-4314-ba8c": {
"title": [
"<b>Solr</b> question about highlighting"
],
"summary": [
"I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
],
**"tag": [
"<b>Solr</b>",
"<b>SolrJ</b>",
"<b>SolrCloud</b>",
"<b>SolrX</b>"
]**
}
}
After searching into the documentation, and running some tests, I found out that setting the parameter hl.preserveMulti in solrconfig.xml:
<str name="hl.preserveMulti">true</str>
doesn't only preserve order of values in a multiValue document as the docs are saying, but it also returns all of the values of the multivalue document in their original order. So if we set the parameter mentioned above and we have the following document in our index:
{
"id": [
"fdc3833a-0e4f-4314-ba8c"
],,
"tag": [
"solr",
"solrJ",
"solrCloud"
"solrX",
"notRelevantTag"
],
"title": "Solr question about highlighting",
"description": "I am working to enable Standard Highlighting on my server with Solr 4.7. My documents contain (among the others) the following.........",
}
the query:
https://<YOUR_PATH>/select?q=solr*&wt=json&indent=true
will give me a highlighted result as:
"highlighting": {
"fdc3833a-0e4f-4314-ba8c": {
"title": [
"<b>Solr</b> question about highlighting"
],
"summary": [
"I am working to enable Standard Highlighting on my server with <b>Solr</b> 4.7. My documents contain (among the others) the following........."
],
**"tag": [
"<b>Solr</b>",
"<b>SolrJ</b>",
"<b>SolrCloud</b>",
"<b>SolrX</b>",
"notRelevantTag"
]**
}
}