【问题标题】:Solr Highlight only in fields that have resultsSolr 仅在有结果的字段中突出显示
【发布时间】:2012-12-01 19:15:11
【问题描述】:

我有一个 solr 查询,我在其中搜索 (webpage_text:*test* OR company_text:*test*)

在我的突出显示中,我将字段设置为webpage_text, company_text。但是现在我总是在突出显示结果中得到两个字段,即使搜索词只在 pages_text 中找到,我也得到 company_text 的突出显示结果,它只是完整的字段。

是否可以只返回匹配字段的亮点?

我尝试了 requireFieldMatch 但这不起作用。

@EDIT:可能是重要信息:这两个字段实际上是由复制字段填充的空字段。这有影响吗?

<field name="company_text" type="text_general" indexed="true" stored="true" multiValued="true" default="" termVectors="true" termPositions="true" termOffsets="true"/>
<field name="webpage_text" type="text_general" indexed="true" stored="true" multiValued="true" default="" termVectors="true" termPositions="true" termOffsets="true"/>

<dynamicField name="*company_*" type="string" indexed="true" stored="true" multiValued="true"/>
<dynamicField name="*talent_*" type="string" indexed="true" stored="true" multiValued="true"/>

<copyField source="company_*" dest="company_text" maxLength="30000000"/>
<copyField source="webpage_*" dest="webpage_text" maxLength="30000000"/>

@EDIT2:似乎复制字段总是出现在突出显示中,即使它们没有匹配项。

【问题讨论】:

标签: solr lucene highlighting


【解决方案1】:

我相信requireFieldMatch 选项是您需要使用的。但是,要使其正常工作,您还需要启用usePhraseHighlighter,然后通过将您的术语括在引号中来确保您正在执行 PhraseQueries。 (例如webpage_text:"*test*"

所以一个例子可能如下:

http://localhost:8983/solr/select/q=webpage_text%3A"*test*"+OR
  +company_text%3A"*test*"&wt=xml&hl=true&hl.fl=webpage_text%2Ccompany_text
  &hl.simple.pre=<em>&hl.simple.post=<%2Fem>
  &hl.requireFieldMatch=true&hl.usePhraseHighlighter=true

您将需要根据需要调整服务器设置并为您的场景调整其他参数。

【讨论】:

  • 我这样做了,但它仍然总是让我返回 2 个字段。即使只有 1 个字段有结果。然后第二个字段只是完整的字段,没有突出显示。
【解决方案2】:

如果没有另外指定,Solr 总是返回所有字段。该字段是否包含在搜索查询中并不重要。匹配的字段会突出显示。

如果您只有两个字段,则返回这两个/所有字段并突出显示其中一个。

【讨论】:

  • 我想你误会了。我确实有 2 个字段,但是当我进行搜索时,这 2 个字段总是在突出显示中返回,即使 2 个字段中的一个没有匹配项。我正在尝试一些事情,我觉得这与它们是复制字段的事实有关。
  • 我明白了。当查询中只包含一个字段时,第二个字段是否也以高亮返回?
  • 是的,如果我将company_text作为搜索字段,将“company_text,webpage_text”作为HL字段,两个字段都会在高亮中返回
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-27
  • 2021-05-12
  • 1970-01-01
  • 2013-08-30
  • 1970-01-01
  • 2012-01-07
  • 2011-03-15
相关资源
最近更新 更多