Lucene安全搜索asp.net c#
我希望这对某人来说是一个非常简单的问题......
基本上我们正在根据 lucene.net 中的文档索引安全信息,该信息存储在名为 viewuserids 和 的 2 个文档字段中viewroleids,因此当我们构建查询时,仅返回用户有权查看访问权限的文档。
查询所需的功能是,如果用户属于 viewroleids 中存储的角色,我们只希望返回文档(这部分工作正常),但是如果 viewuserids索引上的字段包含任何 ID(该字段可能不包含任何值),应忽略 viewroleids,并且只有 viewuserids 中存在的用户才应能够查看该文档。
如上所述,角色部分按预期工作,但我们需要一些帮助来在 API 中构建术语查询,以考虑 viewuserids (有效地覆盖 viewroleids 查询)这是我们目前所拥有的:
BooleanQuery bq = new BooleanQuery();
foreach (int roleId in roleIds)
{
bq.Add(new TermQuery(new Term("viewroleid", roleId.ToString())),BooleanClause.Occur.SHOULD);
}
bq.Add(new TermQuery(new Term("viewuserid", User.Id.ToString())), BooleanClause.Occur.SHOULD);
提前感谢您的帮助
! 这两个字段都存储在未标记化的索引中
Im hoping this would be a really easy question for someone....
Basically we are indexing security information against my documents in lucene.net, the information is stored in 2 document fields called viewuserids and viewroleids, so when we construct a query - only documents which the user has view access to are returned.
The required functionality for a query is that we want only documents to be returned if a user belongs to the roles stored in viewroleids (this bit is working fine), however if viewuserids field contains any ids (the field may not contain any values) on the index the viewroleids should be ignored and only users who are present in viewuserids should be able to see the document.
As mentioned above the role part works as expected, but we need a little help on constucting a term query in the API to take into account the viewuserids (effectively overriding the viewroleids query. This is what we have so far:
BooleanQuery bq = new BooleanQuery();
foreach (int roleId in roleIds)
{
bq.Add(new TermQuery(new Term("viewroleid", roleId.ToString())),BooleanClause.Occur.SHOULD);
}
bq.Add(new TermQuery(new Term("viewuserid", User.Id.ToString())), BooleanClause.Occur.SHOULD);
Thanks in advance for any help!
NOTE:
both fields are stored in the index untokenised
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有多种方法可以做到这一点,但这里是一种:
添加一个字段“hasviewuserids”,如果文档有任何与之关联的 viewuserids,则该字段包含“TRUE”,如果没有,则包含“FALSE”。因此,例如,如果当前用户 ID 为 3 并且处于角色 5 和 6,则查询将如下所示:
There are multiple ways to do this, but here is one:
Add a field "hasviewuserids", which contains "TRUE" if a document has any viewuserids associated with it, and "FALSE" if not. So if, for example, the current userid is 3 and is in roles 5 and 6, the query would look like: