use of org.apache.solr.search.WrappedQuery in project SearchServices by Alfresco.
the class SolrAuthoritySetScorer method createAuthoritySetScorer.
public static SolrAuthoritySetScorer createAuthoritySetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities) throws IOException {
Properties p = searcher.getSchema().getResourceLoader().getCoreProperties();
boolean doPermissionChecks = Boolean.parseBoolean(p.getProperty("alfresco.doPermissionChecks", "true"));
Query key = new SolrAuthoritySetQuery(authorities);
DocSet answer = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key);
if (answer != null) {
// Answer was in the cache, so return it.
return new SolrAuthoritySetScorer(weight, answer, context, searcher);
}
// Answer was not in cache, so build the results, cache and return.
String[] auths = authorities.substring(1).split(authorities.substring(0, 1));
boolean hasGlobalRead = false;
final HashSet<String> globalReaders = GlobalReaders.getReaders();
for (String auth : auths) {
if (globalReaders.contains(auth)) {
hasGlobalRead = true;
break;
}
}
if (hasGlobalRead || (doPermissionChecks == false)) {
// can read all
WrappedQuery wrapped = new WrappedQuery(new MatchAllDocsQuery());
wrapped.setCache(false);
DocSet allDocs = searcher.getDocSet(wrapped);
return new SolrAuthoritySetScorer(weight, allDocs, context, searcher);
}
// Docs for which the authorities have explicit read access.
WrappedQuery wrapped;
wrapped = new WrappedQuery(new SolrReaderSetQuery(authorities));
wrapped.setCache(false);
DocSet readableDocSet = searcher.getDocSet(wrapped);
// Are all doc owners granted read permissions at a global level?
if (globalReaders.contains(PermissionService.OWNER_AUTHORITY)) {
// Get the set of docs owned by the authorities (which they can therefore read).
wrapped = new WrappedQuery(new SolrOwnerSetQuery(authorities));
wrapped.setCache(false);
DocSet authorityOwnedDocs = searcher.getDocSet(wrapped);
// Final set of docs that the authorities can read.
DocSet toCache = readableDocSet.union(authorityOwnedDocs);
searcher.cacheInsert(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key, toCache);
return new SolrAuthoritySetScorer(weight, toCache, context, searcher);
} else {
// for that docs I own that have owner Read rights
wrapped = new WrappedQuery(new SolrReaderSetQuery("|" + PermissionService.OWNER_AUTHORITY));
wrapped.setCache(false);
DocSet ownerReadableDocSet = searcher.getDocSet(wrapped);
wrapped = new WrappedQuery(new SolrOwnerSetQuery(authorities));
wrapped.setCache(false);
DocSet authorityOwnedDocs = searcher.getDocSet(wrapped);
// Docs where the authority is an owner and where owners have read rights.
DocSet docsAuthorityOwnsAndCanRead = ownerReadableDocSet.intersection(authorityOwnedDocs);
// Final set of docs that the authorities can read.
DocSet toCache = readableDocSet.union(docsAuthorityOwnsAndCanRead);
searcher.cacheInsert(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key, toCache);
return new SolrAuthoritySetScorer(weight, toCache, context, searcher);
}
}
Aggregations