Solr - 如何突出显示特定领域的特定术语

Solr - How to highlight specific terms in specific fields

如何突出显示特定字段中的特定术语?

例如,想象以下查询:

foo TITLE("bar")

,我要实现的是所有领域foo的高亮,只有TITLE.

领域的bar

到目前为止,以下方法还没有奏效:

q=<TITLE_field_internal_name>:"bar"hl.fl=&&hl.requireFieldMatch=true

注意:在上面的示例中,TITLE 被正确地重新映射到一个 solr 字段。

大多数突出显示参数支持按字段参数语法:

f.TITLE.hl.<parameter>

鉴于您的语法不是有效的 Solr 语法,它无法知道 TITLE("bar") 指的是名为 TITLE 的字段,您必须提取(或提供)该元数据你自己。

如果您正在查询不同的字段并且只想突出显示在这些字段中命中的术语(即,如果您的查询 title:bar 只在字段 [=14] 中搜索 bar =]),您不必使用每个字段设置,但可以将 hl.requireFieldMatch 设置为 true

By default, false, all query terms will be highlighted for each field to be highlighted (hl.fl) no matter what fields the parsed query refer to. If set to true, only query terms aligning with the field being highlighted will in turn be highlighted.

Note: if the query references fields 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.

最后,经过多次试验和错误,我设法让这个东西工作这里有一些片段:

fq=(_query_:"{!edismax+qf%3D'container_title_en'+v%3D'hormones'}"+OR+_query_:"{!edismax+qf%3D$fqf+v%3D'cancer'}")

fqf=authors_tnss+etc+etc+...

hl.q=(_query_:"{!edismax+qf%3D'container_title_en'+v%3D'hormones'}"+OR+_query_:"{!edismax+qf%3D$fqf+v%3D'cancer'}")

hl.fl=id,external_id_s,etc,etc,...

hl.requireFieldMatch=true

,请注意,如果 hl.fl 字段由 , 分隔,而在我的 fq 自定义 fqf 字段中,它们由 + 分隔。