Lucene 和访问控制(注释的可见性)

发布于 2024-07-26 06:11:47 字数 335 浏览 2 评论 0原文

想象一下全文搜索的简单场景:带评论的文章。 我想也通过评论中的文字搜索文章。 仅此一点就很容易实现。

但并非所有评论都对所有用户可见。 撰写评论的用户还可以限制其对具体角色的可见性(因此评论有 2 个字段:文本和角色)。

是否可以限制 lucene 对文章的搜索,使其仅查找当前用户可见的评论(comment.role 位于当前用户角色的集合内)?

如果是这样,请指出正确的方向,我应该如何去做并编写这样的查询(最好)或 lucene 过滤器。

(我通过 hibernate-search 使用 lucene,但应该没有什么区别)

Imagine this simple scenario for full text search: Articles with Comments. I want to search articles also by text in comments. That alone is fairly simple to implement.

Not all comments are visible to all users though. User that writes comment can also restrict it's visibility to concrete Role (so comment has 2 fields: text and role).

Is it possible to restrict lucene search on articles so it looks only inside comments that are visible for current user (comment.role is inside set of current user's roles)?

If so, please point me to the right direction how should I go about it and write such query (preferably) or lucene filter.

(I'm using lucene through hibernate-search but it should make no difference)

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

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

发布评论

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

评论(3

不如归去 2024-08-02 06:11:47

根据 docs,您可以指定您所在的角色有兴趣作为查询中的另一个字段。 在您的示例中,类似这样的操作应该有效:

text:"user query" AND role:"userRole"

According to the docs, you can just give the role that you are interested in as another field in the query. In your example, something like this should work:

text:"user query" AND role:"userRole"
挽心 2024-08-02 06:11:47

添加到 joeslice 的答案。 如果存在角色层次结构,其中某个角色的权限会将该权限级联到层次结构中的其他角色。 例如,如果授予角色“经理”的权限,则导致“主管”和“主管”的权限。 亦作“副总统”。

在这种情况下,您的查询将是

text:"user query" AND (role:"role1" OR role:"role2" OR role:"role3")

Adding to joeslice's answer. If there is a hierarchy of roles where permission to a role cascades that permission to other roles up in the hierarchy. For example, if permission for role "manager" is granted resulting into permission for "director" & "vice president" as well.

In this case, your query will be

text:"user query" AND (role:"role1" OR role:"role2" OR role:"role3")
も让我眼熟你 2024-08-02 06:11:47

对于这种情况我想不出任何好的解决方案,但我可以想出一些不好的解决方案......

问题是lucene除了文档字段机制之外并没有真正提供任何层次结构支持。

最好的办法是为每条评论创建一个单独的文档。 这样,每个文档都有一个“文本”和一个“角色”字段,因此您知道该角色适用于文本。

问题是,现在评论和文章之间没有良好的关联,因此,例如,如果您有一篇文章包含单词“hibernate”,并且评论包含单词“lucene”,则搜索“hibernate AND” lucene”将找不到它。 您可以尝试通过将文章和所有评论作为额外字段包含在每个文档中来改进这一点,但是这样您的索引就会变得非常臃肿,并且可能会带来安全隐患。

解决此问题的另一种方法是使用编号字段,例如 comment1comment2 等。然后您可以将 role1comment1 匹配>。 如果您对一篇文章有​​多个评论,这将使您的查询变得庞大且效率低下。

I can't think of any good solutions to this situation, but I can come up with some bad ones...

The problem is that lucene doesn't really provide any hierarchy support other than the document-field mechanism.

Your best bet is to create a separate document for every comment. That way every document has one "text" and one "role" fields, so you know that the role applies to the text.

The problem is that now you don't have a good association between comments and article, so for example, if you have an article that contains the word "hibernate" with a comment containing the word "lucene", a search for "hibernate AND lucene" will not find it. You can try to improve on this by including the article and all the comments as extra fields in every document, but then you'd have a really bloated index, and possibly security implications.

Another way to approach this is to have numbered fields like comment1, comment2 etc. Then you can match role1 with comment1. If you have more than a few comments on an article this will make your queries big and inefficient.

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