【问题标题】:How to highlight a searched text inside a document which is indexed in Apache Solr如何突出显示在 Apache Solr 中索引的文档中的搜索文本
【发布时间】: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_*。然而我无法达到这个结果。但是,如果此搜索字符串出现在任何索引字段中,则它会在结果中正确突出显示。

ma​​naged-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" 以突出显示您的字段,这样就可以了。

标签: solr lucene


【解决方案1】:

最后通过修改 ma​​nage-schema.xml 文件中的 _text _ 字段解决了问题。我已将 stored="false" 的值更改为 stored="true",如下语法所示。

<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_

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-31
    • 1970-01-01
    相关资源
    最近更新 更多