List of usage examples for org.apache.solr.search DocSet union
public DocSet union(DocSet other);
From source file:org.alfresco.solr.query.SolrAuthorityScorer.java
License:Open Source License
public static SolrAuthorityScorer createAuthorityScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException { Properties p = searcher.getSchema().getResourceLoader().getCoreProperties(); boolean doPermissionChecks = Boolean.parseBoolean(p.getProperty("alfresco.doPermissionChecks", "true")); Query key = new SolrAuthorityQuery(authority); DocSet answer = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key); if (answer != null) { // Answer was in the cache, so return it. return new SolrAuthorityScorer(weight, answer, context, searcher); }/*from w w w .j a v a 2 s.c o m*/ // Answer was not in cache, so build the results, cache and return. final HashSet<String> globalReaders = GlobalReaders.getReaders(); if (globalReaders.contains(authority) || (doPermissionChecks == false)) { // can read all DocSet allDocs = searcher.getDocSet(new MatchAllDocsQuery()); return new SolrAuthorityScorer(weight, allDocs, context, searcher); } // Docs for which the authority has explicit read access. DocSet readableDocSet = searcher.getDocSet(new SolrReaderQuery(authority)); // 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 authority (which they can therefore read). DocSet authorityOwnedDocs = searcher.getDocSet(new SolrOwnerQuery(authority)); // Final set of docs that the authority can read. DocSet toCache = readableDocSet.union(authorityOwnedDocs); searcher.cacheInsert(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key, toCache); return new SolrAuthorityScorer(weight, toCache, context, searcher); } else { // for that docs I own that have owner Read rights DocSet ownerReadableDocSet = searcher.getDocSet(new SolrReaderQuery(PermissionService.OWNER_AUTHORITY)); DocSet authorityOwnedDocs = searcher.getDocSet(new SolrOwnerQuery(authority)); // Docs where the authority is an owner and where owners have read rights. DocSet docsAuthorityOwnsAndCanRead = ownerReadableDocSet.intersection(authorityOwnedDocs); // Final set of docs that the authority can read. DocSet toCache = readableDocSet.union(docsAuthorityOwnsAndCanRead); searcher.cacheInsert(CacheConstants.ALFRESCO_AUTHORITY_CACHE, key, toCache); return new SolrAuthorityScorer(weight, toCache, context, searcher); } }
From source file:org.alfresco.solr.query.SolrAuthoritySetScorer.java
License:Open Source License
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); }/*ww w. java2 s .c o m*/ // 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); } }
From source file:org.alfresco.solr.query.SolrCachingAuthorityScorer.java
License:Open Source License
public static SolrCachingAuthorityScorer createAuthorityScorer(SolrIndexSearcher searcher, Similarity similarity, String authority, SolrIndexReader reader) throws IOException { // Get hold of solr top level searcher // Execute query with caching // translate reults to leaf docs // build ordered doc list Query key = new SolrCachingAuthorityQuery(authority); DocSet answer = (DocSet) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_AUTHORITY_CACHE, key); if (answer != null) { return new SolrCachingAuthorityScorer(similarity, answer, reader); }//from w w w . ja va2s .c o m HashSet<String> globalReaders = (HashSet<String>) searcher.cacheLookup( AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_GLOBAL_READERS); if (globalReaders.contains(authority)) { // can read all OpenBitSet allLeafDocs = (OpenBitSet) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_ALL_LEAF_DOCS); DocSet toCache = new BitDocSet(allLeafDocs); searcher.cacheInsert(AlfrescoSolrEventListener.ALFRESCO_AUTHORITY_CACHE, key, toCache); return new SolrCachingAuthorityScorer(similarity, toCache, reader); } DocSet readableDocSet = searcher.getDocSet(new SolrCachingReaderQuery(authority)); if (globalReaders.contains(PermissionService.OWNER_AUTHORITY)) { DocSet authorityOwnedDocs = searcher.getDocSet(new SolrCachingOwnerQuery(authority)); DocSet toCache = readableDocSet.union(authorityOwnedDocs); searcher.cacheInsert(AlfrescoSolrEventListener.ALFRESCO_AUTHORITY_CACHE, key, toCache); return new SolrCachingAuthorityScorer(similarity, toCache, reader); } else { // for that docs I own that have owner Read rights DocSet ownerReadableDocSet = searcher .getDocSet(new SolrCachingReaderQuery(PermissionService.OWNER_AUTHORITY)); DocSet authorityOwnedDocs = searcher.getDocSet(new SolrCachingOwnerQuery(authority)); DocSet docsAuthorityOwnsAndCanRead = ownerReadableDocSet.intersection(authorityOwnedDocs); DocSet toCache = readableDocSet.union(docsAuthorityOwnsAndCanRead); searcher.cacheInsert(AlfrescoSolrEventListener.ALFRESCO_AUTHORITY_CACHE, key, toCache); return new SolrCachingAuthorityScorer(similarity, toCache, reader); } }
From source file:org.alfresco.solr.query.SolrDeniedScorer.java
License:Open Source License
public static SolrDeniedScorer createDenyScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException { DocSet deniedDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_DENIED_CACHE, authority); if (deniedDocs == null) { // Cache miss: query the index for ACL docs where the denial matches the authority. DocSet aclDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_DENIED, authority))); // Allocate a bitset to store the results. deniedDocs = new BitDocSet(new FixedBitSet(searcher.maxDoc())); // Translate from ACL docs to real docs for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) { int docID = it.nextDoc(); // Obtain the ACL ID for this ACL doc. long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID) .get(docID);//from ww w. j a v a 2 s .c om SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID); Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID)); // Find real docs that match the ACL ID DocSet docsForAclId = searcher.getDocSet(query); deniedDocs = deniedDocs.union(docsForAclId); // Exclude the ACL docs from the results, we only want real docs that match. // Probably not very efficient, what we really want is remove(docID) deniedDocs = deniedDocs.andNot(aclDocs); } searcher.cacheInsert(CacheConstants.ALFRESCO_DENIED_CACHE, authority, deniedDocs); } return new SolrDeniedScorer(weight, deniedDocs, context, searcher); }
From source file:org.alfresco.solr.query.SolrDenySetScorer.java
License:Open Source License
public static SolrDenySetScorer createDenySetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities, LeafReader reader) throws IOException { DocSet deniedDocSet = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_DENIED_CACHE, authorities); if (deniedDocSet == null) { String[] auths = authorities.substring(1).split(authorities.substring(0, 1)); deniedDocSet = new BitDocSet(new FixedBitSet(searcher.maxDoc())); BooleanQuery.Builder bQuery = new BooleanQuery.Builder(); for (String current : auths) { bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_DENIED, current)), Occur.SHOULD); }/*w w w .j a v a 2 s . co m*/ DocSet aclDocs = searcher.getDocSet(bQuery.build()); BooleanQuery.Builder aQuery = new BooleanQuery.Builder(); for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) { int docID = it.nextDoc(); // Obtain the ACL ID for this ACL doc. long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID) .get(docID); SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID); Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID)); aQuery.add(query, Occur.SHOULD); if ((aQuery.build().clauses().size() > 999) || !it.hasNext()) { DocSet docsForAclId = searcher.getDocSet(aQuery.build()); deniedDocSet = deniedDocSet.union(docsForAclId); aQuery = new BooleanQuery.Builder(); } } // Exclude the ACL docs from the results, we only want real docs that match. // Probably not very efficient, what we really want is remove(docID) deniedDocSet = deniedDocSet.andNot(aclDocs); searcher.cacheInsert(CacheConstants.ALFRESCO_DENIED_CACHE, authorities, deniedDocSet); } // TODO: cache the full set? e.g. searcher.cacheInsert(CacheConstants.ALFRESCO_READERSET_CACHE, authorities, readableDocSet) // plus check of course, for presence in cache at start of method. return new SolrDenySetScorer(weight, deniedDocSet, context, searcher); }
From source file:org.alfresco.solr.query.SolrReaderScorer.java
License:Open Source License
public static SolrReaderScorer createReaderScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authority) throws IOException { DocSet readableDocs = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_READER_CACHE, authority); if (readableDocs == null) { // Cache miss: query the index for ACL docs where the reader matches the authority. DocSet aclDocs = searcher.getDocSet(new TermQuery(new Term(QueryConstants.FIELD_READER, authority))); // Allocate a bitset to store the results. readableDocs = new BitDocSet(new FixedBitSet(searcher.maxDoc())); // Translate from ACL docs to real docs for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) { int docID = it.nextDoc(); // Obtain the ACL ID for this ACL doc. long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID) .get(docID);//w w w .j a v a 2 s. c o m SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID); Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID)); DocSet docsForAclId = searcher.getDocSet(query); readableDocs = readableDocs.union(docsForAclId); // Exclude the ACL docs from the results, we only want real docs that match. // Probably not very efficient, what we really want is remove(docID) readableDocs = readableDocs.andNot(aclDocs); } searcher.cacheInsert(CacheConstants.ALFRESCO_READER_CACHE, authority, readableDocs); } return new SolrReaderScorer(weight, readableDocs, context, searcher); }
From source file:org.alfresco.solr.query.SolrReaderSetScorer.java
License:Open Source License
public static SolrReaderSetScorer createReaderSetScorer(Weight weight, LeafReaderContext context, SolrIndexSearcher searcher, String authorities, LeafReader reader) throws IOException { DocSet readableDocSet = (DocSet) searcher.cacheLookup(CacheConstants.ALFRESCO_READER_CACHE, authorities); if (readableDocSet == null) { String[] auths = authorities.substring(1).split(authorities.substring(0, 1)); readableDocSet = new BitDocSet(new FixedBitSet(searcher.maxDoc())); BooleanQuery.Builder bQuery = new BooleanQuery.Builder(); for (String current : auths) { bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_READER, current)), Occur.SHOULD); }/*from w w w .j av a 2s. c o m*/ DocSet aclDocs = searcher.getDocSet(bQuery.build()); BooleanQuery.Builder aQuery = new BooleanQuery.Builder(); for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) { int docID = it.nextDoc(); // Obtain the ACL ID for this ACL doc. long aclID = searcher.getSlowAtomicReader().getNumericDocValues(QueryConstants.FIELD_ACLID) .get(docID); SchemaField schemaField = searcher.getSchema().getField(QueryConstants.FIELD_ACLID); Query query = schemaField.getType().getFieldQuery(null, schemaField, Long.toString(aclID)); aQuery.add(query, Occur.SHOULD); if ((aQuery.build().clauses().size() > 999) || !it.hasNext()) { DocSet docsForAclId = searcher.getDocSet(aQuery.build()); readableDocSet = readableDocSet.union(docsForAclId); aQuery = new BooleanQuery.Builder(); } } // Exclude the ACL docs from the results, we only want real docs that match. // Probably not very efficient, what we really want is remove(docID) readableDocSet = readableDocSet.andNot(aclDocs); searcher.cacheInsert(CacheConstants.ALFRESCO_READER_CACHE, authorities, readableDocSet); } // TODO: cache the full set? e.g. searcher.cacheInsert(CacheConstants.ALFRESCO_READERSET_CACHE, authorities, readableDocSet) // plus check of course, for presence in cache at start of method. return new SolrReaderSetScorer(weight, readableDocSet, context, searcher); }