Search in sources :

Example 6 with WrappedQuery

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);
    }
}
Also used : Query(org.apache.lucene.search.Query) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) WrappedQuery(org.apache.solr.search.WrappedQuery) WrappedQuery(org.apache.solr.search.WrappedQuery) Properties(java.util.Properties) MatchAllDocsQuery(org.apache.lucene.search.MatchAllDocsQuery) DocSet(org.apache.solr.search.DocSet)

Aggregations

DocSet (org.apache.solr.search.DocSet)6 WrappedQuery (org.apache.solr.search.WrappedQuery)6 Term (org.apache.lucene.index.Term)3 BooleanQuery (org.apache.lucene.search.BooleanQuery)3 TermQuery (org.apache.lucene.search.TermQuery)3 HashSet (java.util.HashSet)2 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 FixedBitSet (org.apache.lucene.util.FixedBitSet)2 BitDocSet (org.apache.solr.search.BitDocSet)2 DocIterator (org.apache.solr.search.DocIterator)2 Properties (java.util.Properties)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)1 Query (org.apache.lucene.search.Query)1 SolrIndexSearcher (org.apache.solr.search.SolrIndexSearcher)1