简体   繁体   English

如何将Hibernate Search(Lucene)与分页和ACL结合起来

[英]How to combine Hibernate Search (Lucene) with paging and ACLs

I am using Spring Security with ACLs to secure the documents in my application. 我正在使用带有ACL的Spring Security来保护我的应用程序中的文档。 On the other hand I use Hibernate Search (on top of lucene) to search for the documents. 另一方面,我使用Hibernate Search(在lucene之上)来搜索文档。 This search also support paging. 此搜索还支持分页。 ( Documents are only meta data of documents stored in a Database. ) 文档只是存储在数据库中的文档的元数据。

FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager);
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Document.class).get();
Query query = queryBuilder.keyword().onFields(fieldNames.toArray(new String[0])).matching(searchQuery)
            .createQuery();

FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(query, Document.class);
fullTextQuery.setFirstResult(pageable.getFirstItem());
fullTextQuery.setMaxResults(pageable.getPageSize());

Now I have to combine the paging with the ACLs. 现在我必须将分页与ACL结合起来。 The only idea I have at the moment, is to remove the paging form the FullTextQuery, read all search result documents, filter them by there ACLs and then do the paging by hand. 我目前唯一的想法是从FullTextQuery中删除分页,读取所有搜索结果文档,通过ACL过滤它们,然后手动进行分页。 But I don't like that solution, because it loads all the documents, instead of only the one for the page. 但我不喜欢这个解决方案,因为它加载所有文档,而不是只加载页面的文档。

Does anybody have a better idea? 有没有人有更好的主意?

If your ACL is not too complex, that is you have a small, finite number of levels, then I suggest to Use Filter and Bitset to implement it. 如果你的ACL不是太复杂,那就是你有一个小的,有限数量的级别,那么我建议使用Filter和Bitset来实现它。

And here you'll find additional examples ACL implementation with Filters http://java.dzone.com/articles/how-implement-row-level-access 在这里,您将找到使用过滤器http://java.dzone.com/articles/how-implement-row-level-access进行 ACL实施的其他示例

Here you'll find a cached bitset filter implementation which has been in production for at least 5 years (it's my open source webapp for a searchable parallel text corpus) 在这里,您将找到一个缓存的bitset过滤器实现,该实现已经生产了至少5年(它是我的开源webapp,用于可搜索的并行文本语料库)

Look for the addSourceFilter method http://code.google.com/p/hunglish-webapp/source/browse/trunk/src/main/java/hu/mokk/hunglish/lucene/LuceneQueryBuilder.java 查找addSourceFilter方法http://code.google.com/p/hunglish-webapp/source/browse/trunk/src/main/java/hu/mokk/hunglish/lucene/LuceneQueryBuilder.java

I have hit the same problem too and I don't think there is a simple answer. 我也遇到了同样的问题,我认为没有一个简单的答案。

I think there are only two solutions. 我认为只有两种解决方案。 The one you have suggested which has performance problems you've described as you have to load the documents and resolve the ACL for each result and then do your own paging. 你所建议的那个有你所描述的性能问题,因为你必须加载文件并解析每个结果的ACL,然后自己进行分页。 The alternative is to push this work to the indexing side and index your ACL in Lucene. 另一种方法是将此工作推送到索引端并在Lucene中索引ACL。 This gives you the search performance, hiding the results which a user can't see by adding filter terms based on the current user/group/permissions/roles but at the expense of maintaining the index with ACL information. 这为您提供搜索性能,通过基于当前用户/组/权限/角色添加过滤器术语来隐藏用户无法看到的结果,但代价是使用ACL信息维护索引。 If your ACL is simple then this may be an option. 如果您的ACL很简单,那么这可能是一个选项。 If your ACL is hierarchical then it's still an option but more complicated. 如果您的ACL是分层的,那么它仍然是一个选项,但更复杂。 Its also tricky to keep your index upto date with the ACL. 使用ACL保持索引最新也很棘手。

The fact that you are starting to look into this sort of functionality may indicate that you are beginning to stretch your Database/Hibernate/Lucene solution. 您开始研究此类功能的事实可能表明您开始扩展Database / Hibernate / Lucene解决方案。 Maybe a content repository like Jackrabbit may be a better fit? 也许像Jackrabbit这样的内容库可能更合适? I guess this is probably a step too far but it may be worth taking a look to see how it does it. 我想这可能是一个太过分的步骤,但值得一看,看看它是如何做到的。 Alternatively take a look at SOLR, particularly this issue which describes what a thorny problem it is. 或者看看SOLR,特别是这个问题描述了它是一个棘手的问题。

是我使用纯Lucene查询(在Hibernate Search之上)的复杂用户/组/角色分层ACL系统的ACL实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM