Solr 1.4 中的高亮显示 - requireFieldMatch

发布于 2024-08-26 19:15:08 字数 645 浏览 13 评论 0原文

我有一个对象

Title   : foo
Summary : foo bar
Body    : this is a published story about a foo and a bar

所有三个对象都设置为stored=true 的字段。

用户在我的系统中搜索“

"foo"

我想在所有三个位置突出显示 foo”这个词。

用户在标题中搜索单词 foo

"title:foo"

我只想在标题中突出显示 foo 。

当我添加 hl.requireFieldMatch=truehl.usePhraseHighlighter=true 作为我对 SOLR 查询的一部分,在执行通用非字段操作时,我无法在所有三个地方突出显示搜索。有没有办法让这两种情况都起作用?

我关闭了这两个项目,但我添加了查询的一些字段部分,用户看不到这些部分,例如仅显示已发布的项目。问题是

(foo AND status:published)

当用户仅搜索单词“foo”时,导致正文中发布的单词突出显示。

I have an object

Title   : foo
Summary : foo bar
Body    : this is a published story about a foo and a bar

All three are set up as fields with stored=true.

The user searches across my system for the word

"foo"

I would like to highlight foo in all three places.

The user searches for the word foo in the title

"title:foo"

I only want to highlight foo within the title.

When I added
hl.requireFieldMatch=true and hl.usePhraseHighlighter=true as part of my query over to SOLR I am unable to get the highlighting in all three places when doing a generic non fielded search. Is there a way to get both scenarios to work?

I had these two items turned off, but I am adding in some fielded portions of the query that the user does not see which only display Published items for instance. the problem is

(foo AND status:published)

is causing the word published in the body to highlight when the user only searched for the word "foo".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赢得她心 2024-09-02 19:15:08

事实证明,与 solr / lucene 相比,这可能更像是 act_as_solr 的怪癖。

我利用了 solr 中的 fq 选项
http://wiki.apache.org/solr/CommonQueryParameters#fq

查询否更长的看起来像

(foo AND status:published)

看起来更像是

q=foo&fq=status:published

当它击中 solr 时

fq 不会影响突出显示,而且这似乎是一个更好的方法,因为您可以获得一些 solr 缓存的好处。

仍然存在一个错误/功能未使用acts_as_solr 实现,它也需要利用这一点。

例如,如果我的模型名为“文章”,并且用户搜索“文章”一词,AAS 会在幕后构建一个查询,如下所示。

(article AND type_t:article)

这会导致相同的问题,即当您不想要它时,“文章”一词会在各处突出显示以及当用户搜索术语“文章”时,他们会返回系统中的每个对象。

快速浏览了一下 acts_as_solr 的 GitHub 分支,没有看到任何人已经实现了这个。 parser_methods.rb 中有很好的#TODO

Turns out that this may be more of a quirk with act_as_solr than it is with solr / lucene.

I took advantage of the fq option within solr
http://wiki.apache.org/solr/CommonQueryParameters#fq

the query no longer looks like

(foo AND status:published)

Looks more like

q=foo&fq=status:published

when it hits solr

The fq does not impact highlighting and it seems like a better way to do this since you get some solr caching benefits.

There is still a bug / feature not implemented with acts_as_solr which needs to take advantage of this as well.

For instance if my model is named article, and the user searches for the word article, AAS is building a query behind the scenes that looks like

(article AND type_t:article)

This causes the same problem that the word article highlights all over the place when you don't want it to, as well as when the user searches for the term "article" they get back every single object in the system.

Took a quick look at GitHub forks of acts_as_solr and didn't see anyone that has implemented this yet. There is nice #TODO sitting there within parser_methods.rb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文