如何在Apache Solr中索引的文档中突出显示搜索到的文本



我使用Apache Solr 8.6在Linux中使用POST工具对文档进行索引,如《Apache Solr参考指南》中所述。

POST工具命令

bin/post -c testcore /testdocs/

文档已成功建立索引。现在,当我在Solr Admin UI中搜索字符串(例如:hello(时,它将返回匹配的文档。

现在我想突出显示这个字符串"你好">作为内容存在于文档中。但我无法做到这一点。我试过启用高亮显示,并在hl.fl=text_*中输入text_*。但我无法达到这个结果。但是,如果搜索到的字符串出现在任何索引字段中,则它会在结果中正确突出显示。

托管架构.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"/>

最终通过修改manage-schema.xml文件中的_text_字段解决了问题。我已经改变了存储="strong"的值;false";存储=";真">如下语法所示。

<field name="_text_" type="text_general" indexed="true" stored="true" multiValued="false"/>

然后我重新启动了solr,并对文档进行了重新索引。

现在我已经启动了查询以突出显示文本,如下所示。在这个查询中,我使用了hl=on&hl.fl=_text _以突出显示注释。

查询以突出显示搜索到的字符串

http://localhost:8983/solr/testcore/select?q=_text_%3a*hello*&hl=on&hl.fl=_text_

最新更新