Lucene中的多索引搜索(hibernate搜索)

发布于 2024-07-26 16:02:03 字数 305 浏览 4 评论 0原文

Lucene Feautures 官方网站声明 lucene 支持“具有合并结果的多索引搜索”。

是否可以通过休眠搜索以某种方式做到这一点?

我的用例:Aricle with Comments。 我想要两个单独的索引:一个用于文章,一个用于评论。 我希望能够在评论之一中通过匹配找到文章。 从用户的角度来看,我希望搜索“查看”文章文本及其评论并返回文章列表。 (我知道我可以通过将所有评论存储为文章文档中的字段来实现这一点,但我想对评论中的搜索应用过滤器。)

是否有可能使用本机 Lucene 或者我/我完全没有抓住重点?

Official Lucene Feautures site states that lucene supports "multiple-index searching with merged results".

Is it possible to do this with hibernate search somehow?

My usecase: Aricle with Comments. I want to have two separate indices: one for articles and one for comments. I want to be able to find article also by match in one of comments. From user perspective, I want search that "looks" into article text and also its comments and returns list of articles.
(I know I can implement this by storing all comments as fields inside article document, but I want to apply filters on search in comments.)

Is it even possible with native Lucene or I/m completely missing the point?

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

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

发布评论

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

评论(2

又爬满兰若 2024-08-02 16:02:04

给每篇文章一个 ID 会更容易。 然后将评论存储在文章之外,但有一个字段告诉您评论是针对哪篇文章的。 搜索两个索引(或者具有不同字段(称为“文章”和“评论”)的同一索引,然后根据文章 ID 进行合并。这样您就可以对文章查询和评论查询的结果分别设置过滤器。

It would be easier to give each article an ID. Then store the comments outside the articles but with a field that tells you what article a comment is on. Search both indexes (or the same index with different fields called "article" and "comment) and then merge on the article ID. This way you could set filters seperately on the results from the article query and the comment query.

爱的那么颓废 2024-08-02 16:02:03

你的整个解释似乎很模糊。 Hibernate Search 似乎很适合您的用例,前提是您有一个适当的域模型,这意味着一篇文章以某种方式链接到评论,例如通过 OneToMany 关联。 如果文章和评论之间没有关系,你怎么知道评论属于哪一篇文章呢?

拥有这样的域模型将解决您的用例 - 能够在文章和评论中搜索,但返回文章列表。

也就是说,可以为文章和评论保留单独的 Lucene 索引。 事实上,如果将 @Indexed 添加到每个类,则会为每个类创建一个索引。 然而,搜索变得更加复杂。

我建议在文章上使用@Indexed,与文章中的评论建立正确的映射关系,并在其上使用@IndexedEmbedded。

如果您想要更多帮助,您确实必须发布您的域模型或提供有关您的需求/用例的更多信息。

——哈代

Your whole explanation seems vague. Hibernate Search seems like a good fit for your use case, provided that you have a proper domain model, meaning an article which is somehow linked to the comments, via a OneToMany association for example. If there is no relation between Article and Comment how would you know anyway to which article a Comment belongs?

Having such a domain model will solve your use case - being able to search in Articles and Comments, but return a list of Articles.

That said, it is possible to keep a separate Lucene index for Article and Comment. In fact, if you add @Indexed to each class, one index per class is created. However, the search becomes more complex.

I recommend to use @Indexed on Article, have a properly mapped relationship to Comment in Article and use @IndexedEmbedded on it.

If you want more hel you really have to post your domain model or provide more information about your requirements/usecases.

--Hardy

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