Solr highlighting does not work with multiple fiel

2019-08-20 09:42发布

问题:

I have a dynamic text field bar_* in my index and want Solr to return highlightings for that field. So what I run is:

q=gold&hl=true&hl.fl=bar_*

It works as expected BUT in case I add some more fields to hl.fl it stops working. E.g.

q=gold&hl=true&hl.fl=bar_*,foo

Notes:

  • bar_* and foo fields are in the index/schema and there is no error here.
  • just rewriting request as q=gold&hl=true&hl.fl=bar_*&hl.fl=foo or q=gold&hl=true&hl.fl=bar_* foo does NOT help.
  • I didn't find any bugs in Solr JIRA on that topic.

Does anyone have an idea how to bit this. The possible workarounds that I see are:

  1. Use hl.fl=*. But this one is not good for performance.
  2. Explicitly specify all possible fields names for my dynamic field. But I don't like that at all.

回答1:

try

q=gold&hl=true&hl.fl=bar_*&hl.fl=foo


回答2:

After digging into Solr sources (org.apache.solr.highlight.SolrHighlighter#getHighlightFields) I have found a workaround for this. As appears Solr interprets hl.fl content as a regular expression pattern. So I've specified hl.fl as:

hl.fl=bar_*|foo

I.e. using | instead of comma. That worked perfectly for me.

Btw, I have found no documentation of this in the internet.



标签: solr