Hibernate Search 能否通过用户可访问性来限制结果?
我正在使用休眠。我正在寻找一个免费的文本引擎。
在我调查之前,我需要你的经验。
我的应用程序中有用户、角色和对象表。其中用户连接到一个或多个角色,角色连接到一个或多个对象。
在我的自由文本搜索中,用户只能访问对象表允许他观看的数据。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您所描述的模型的外观,Hibernate Search 将能够轻松地为您提供所需的内容。
听起来您正在寻找嵌入式索引和过滤器的组合。我假设对象和角色之间存在多对多关系。如果是这样,您在 Object 中可能有类似的内容:
要获取角色并将它们嵌入到为 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:
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.
看看这个:
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
这是两个独立的问题:
而对于第二个问题,您可以轻松地使用 Hibernate Search(即 Apache Lucene) > 进行一些集成),对于第一个,您应该在使用 lucene 搜索之前集中精力选择要搜索的正确内容。
These are two separate problems:
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.
为了将用户限制为仅某些数据,我假设您的数据将映射到可访问的角色。如果是这种情况,您还需要为您的角色对象建立索引。然后使用@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.