【发布时间】:2021-03-16 13:46:59
【问题描述】:
如Apache Solr Reference Guide 中所述,我正在使用 Apache Solr 8.6 在 Linux 中使用 POST 工具对文档进行索引。
POST 工具命令
bin/post -c testcore /testdocs/
文档已成功编入索引。现在,当我在 Solr Admin UI 中搜索字符串 eg: hello 时,它正在返回匹配的文档。
现在我想突出显示作为内容存在于文档中的这个字符串 "hello"。但我无法达到同样的效果。 我尝试启用突出显示并在 hl.fl=text_* 中输入 text_*。然而我无法达到这个结果。但是,如果此搜索字符串出现在任何索引字段中,则它会在结果中正确突出显示。
在 managed-schema.xml 中,我添加了如下所示的内容和文本字段。
<field name="content" type="text_general" indexed="false" stored="true" multiValued="false"/>
<field name="text" type="text_general" indexed="true" stored="false" multiValued="true"/>
我尝试过以下查询:
http://localhost:8983/solr/testcore/select?q=_text_%3a*hello*&hl=true&hl.fl=content&hl.usephrasehighlighter=true
http://localhost:8983/solr/testcore/select?q=_text_%3a*hello*&hl=true&hl.fl=text_*&hl.usephrasehighlighter=true
如果您能进一步指导我,将不胜感激。
编辑:根据建议
我已经更改了如下所示的内容和文本字段,但它也不起作用。这意味着当我搜索文本字符串时,它不会将文档内的搜索字符串突出显示为内容。
<field name="content" type="text_general" indexed="true" stored="true" multiValued="false"/>
<field name="text" type="text_general" indexed="true" stored="true" multiValued="true"/>
【问题讨论】:
-
所以突出显示适用于
hl.fl=text_*,但不适用于hl.fl=content(这不是很清楚)?这些字段是如何定义的(field+fieldType)? -
没有两个查询都不起作用..我尝试了两种方式。我已将托管 schema.xml 中的内容和文本字段定义为
-
好的,请编辑您的问题,让每个人都清楚(在 cmets 中不可读)。
-
我已更新问题中的 managed-schema.xml 字段 sn-p
-
好的,您需要同时设置
indexed="true"和stored="true"以突出显示您的字段,这样就可以了。