Hibernate Search 能否通过用户可访问性来限制结果?

发布于 2024-09-04 20:17:31 字数 176 浏览 10 评论 0原文

我正在使用休眠。我正在寻找一个免费的文本引擎。

在我调查之前,我需要你的经验。

我的应用程序中有用户、角色和对象表。其中用户连接到一个或多个角色,角色连接到一个或多个对象。

在我的自由文本搜索中,用户只能访问对象表允许他观看的数据。

Hibernate 搜索可以帮助我吗?

I am using Hibernate. I am looking for a free text engine.

Before I investigate into it I need your experience.

I have in my applications user, role and object table. Where a user is connected to one or more roles, and a role is connected to one or more objects.

In my free text search, the user can reach only data that he is allowed to watch by object table.

Can Hibernate search help me with it?

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

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

发布评论

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

评论(4

哀由 2024-09-11 20:17:31

根据您所描述的模型的外观,Hibernate Search 将能够轻松地为您提供所需的内容。

听起来您正在寻找嵌入式索引和过滤器的组合。我假设对象和角色之间存在多对多关系。如果是这样,您在 Object 中可能有类似的内容:

@ManyToMany
@JoinTable(name = "object_role",
            joinColumns = @JoinColumn(name = "object_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles = new HashSet<Role>();

要获取角色并将它们嵌入到为 Object 创建的索引中,您只需将 @IndexedEmbedded(prefix = "somPrefixName") 放在 <代码>@ManyToMany。

然后,您可以使用 @FullTextFilterDef 定义一个过滤器,该过滤器查看此嵌入索引并按给定角色(可能是运行搜索的用户的角色)进行过滤。这将确保搜索查询仅返回与给定角色相关的对象。

简而言之,Hibernate Search 将能够提供您所需要的(假设我正确理解您的要求)。如果您愿意,我很乐意提供更多详细信息。

Based on what you have described your model to look like, Hibernate Search will be able to give you what you need quite easily.

It sounds like you are looking for a combination of an embedded index and a filter. I assume that you have a many to many relationship between Object and Role. If so you probably have something like this in Object:

@ManyToMany
@JoinTable(name = "object_role",
            joinColumns = @JoinColumn(name = "object_id"),
            inverseJoinColumns = @JoinColumn(name = "role_id"))
private Set<Role> roles = new HashSet<Role>();

To take the roles and embed them as part of the index created for Object, you need to just put @IndexedEmbedded(prefix = "somPrefixName") above @ManyToMany.

You can then define a filter using @FullTextFilterDef that looks at this embedded index and filters by a given role (which would presumably be the role of the user that is running the search). This will ensure that only Objects related to the given Role are returned by the search query.

In short, Hibernate Search will be able to provide what you need (assuming I understand your requirement correctly). I will be happy to give more detail on how if you would like.

哑剧 2024-09-11 20:17:31

看看这个:

http://lucene. apache.org/java/2_4_0/api/org/apache/lucene/search/Filter.html

我认为这是实现您想要的内容的正确方法。真的不知道这是如何集成到休眠搜索中的,但希望有一种方法可以以某种方式向查询添加过滤器。

稍后编辑:

看起来有:

http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-query.html#query-filter

Check this out:

http://lucene.apache.org/java/2_4_0/api/org/apache/lucene/search/Filter.html

I think this is the proper way to implement what you want. Don't really know how is this integrated into hibernate-search, but hopefully there is a way to add a filter to a query somehow.

Later edit:

it looks like there is:

http://docs.jboss.org/hibernate/stable/search/reference/en/html/search-query.html#query-filter

剩一世无双 2024-09-11 20:17:31

这是两个独立的问题:

  • 限制用户在实际搜索内容中能够搜索的
  • 内容

而对于第二个问题,您可以轻松地使用 Hibernate Search(即 Apache Lucene) > 进行一些集成),对于第一个,您应该在使用 lucene 搜索之前集中精力选择要搜索的正确内容。

These are two separate problems:

  • restricting which content an user is able to search within
  • actually searching the content

While for the second problem you can easily use Hibernate Search (that is just Apache Lucene with a bit of integration), for the first one you should concentrate on selecting the right content you want to search before searching it with lucene.

夜光 2024-09-11 20:17:31

为了将用户限制为仅某些数据,我假设您的数据将映射到可访问的角色。如果是这种情况,您还需要为您的角色对象建立索引。然后使用@IndexedEmbedded注释来进行一对多或一对一关联。

然后你可以构建你的查询,如下所示:
"text:+ input.getSearchText() + "+role.roleText:" + currentUser.getRole();

这可能有效也可能无效,具体取决于用户管理系统的复杂程度。

To restrict user to only certain data, i am assuming your data will be mapped to accessible roles. If this is the case, you need to index your role object also. Then use @IndexedEmbedded annotation to with the one-to-many or one-to-one association.

Then you can construct your query like:
"text:+ input.getSearchText() + "+role.roleText:" + currentUser.getRole();

This may or may not work depending on how complex your user management system is.

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