Example usage for org.apache.solr.search DocSet iterator

List of usage examples for org.apache.solr.search DocSet iterator

Introduction

In this page you can find the example usage for org.apache.solr.search DocSet iterator.

Prototype

public DocIterator iterator();

Source Link

Document

Returns an iterator that may be used to iterate over all of the documents in the set.

Usage

From source file:com.doculibre.constellio.solr.handler.component.ConstellioAuthorizationComponent.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override// w w w . j  a v a  2  s.c  o  m
public void prepare(ResponseBuilder rb) throws IOException {
    SolrQueryRequest req = rb.req;
    SolrIndexSearcher searcher = req.getSearcher();
    //IndexReader reader = req.getSearcher().getReader();
    SolrParams params = req.getParams();

    // A runtime param can skip
    if (!params.getBool(ENABLE, true)) {
        return;
    }

    Query query = rb.getQuery();
    String qstr = rb.getQueryString();
    if (query == null || qstr == null) {
        return;
    }

    ConstellioUser user;
    String userIdStr = params.get(ConstellioSolrQueryParams.USER_ID);
    if (userIdStr != null) {
        UserServices userServices = ConstellioSpringUtils.getUserServices();
        try {
            user = userServices.get(new Long(userIdStr));
        } catch (NumberFormatException e) {
            user = null;
        }
    } else {
        user = null;
    }

    String collectionName = params.get(ConstellioSolrQueryParams.COLLECTION_NAME);
    RecordCollectionServices collectionServices = ConstellioSpringUtils.getRecordCollectionServices();
    FederationServices federationServices = ConstellioSpringUtils.getFederationServices();
    RecordCollection collection = collectionServices.get(collectionName);

    List<TermQuery> restrictedCollectionQueries = new ArrayList<TermQuery>();
    if (collection.isFederationOwner()) {
        List<RecordCollection> includedCollections = federationServices.listIncludedCollections(collection);
        for (RecordCollection includedCollection : includedCollections) {
            if (includedCollection.hasSearchPermission()
                    && (user == null || !user.hasSearchPermission(includedCollection))) {
                restrictedCollectionQueries.add(new TermQuery(
                        new Term(IndexField.COLLECTION_ID_FIELD, "" + includedCollection.getId())));
            }
        }
    }

    // User must be logged in to see private records
    if (user != null) {
        String luceneQueryStr = params.get(ConstellioSolrQueryParams.LUCENE_QUERY);
        if (StringUtils.isBlank(luceneQueryStr)) {
            return;
        }

        IndexSchema schema = req.getSchema();
        SolrQueryParser queryParser = new SolrQueryParser(rb.getQparser(), IndexField.DEFAULT_SEARCH_FIELD);
        Query luceneQuery;
        try {
            luceneQuery = queryParser.parse(luceneQueryStr);
        } catch (SyntaxError e) {
            log.error("Error parsing lucene query " + luceneQueryStr, e);
            return;
        }
        // Create a new query which will only include private records
        BooleanQuery privateRecordQuery = new BooleanQuery(true);
        privateRecordQuery.add(luceneQuery, BooleanClause.Occur.MUST);
        for (TermQuery restrictionCollectionQuery : restrictedCollectionQueries) {
            privateRecordQuery.add(restrictionCollectionQuery, BooleanClause.Occur.MUST_NOT);
        }

        TermQuery privateRecordTQ = new TermQuery(new Term(IndexField.PUBLIC_RECORD_FIELD, "F"));
        privateRecordQuery.add(privateRecordTQ, BooleanClause.Occur.MUST);

        DocSet privateRecordIdDocSet = searcher.getDocSet(privateRecordQuery);

        if (privateRecordIdDocSet.size() > 0) {
            RecordServices recordServices = ConstellioSpringUtils.getRecordServices();
            ACLServices aclServices = ConstellioSpringUtils.getACLServices();
            ConnectorManagerServices connectorManagerServices = ConstellioSpringUtils
                    .getConnectorManagerServices();

            List<Record> privateRecords = new ArrayList<Record>();
            DocIterator docIt = privateRecordIdDocSet.iterator();
            while (docIt.hasNext()) {
                int docId = docIt.nextDoc();
                Document luceneDoc = searcher.doc(docId);
                Long recordId = new Long(luceneDoc.get(IndexField.RECORD_ID_FIELD));
                Record record = recordServices.get(recordId, collection);
                privateRecords.add(record);
            }
            // First pass : Remove ACL authorized records
            List<Record> unevaluatedPrivateRecords = aclServices.removeAuthorizedRecords(privateRecords, user);
            if (!unevaluatedPrivateRecords.isEmpty()) {
                Set<UserCredentials> userCredentials = user.getUserCredentials();
                // Second pass : Ask the connector manager
                ConnectorManager connectorManager = connectorManagerServices.getDefaultConnectorManager();
                List<Record> authorizedRecords = connectorManagerServices
                        .authorizeByConnector(unevaluatedPrivateRecords, userCredentials, connectorManager);
                List<Record> unauthorizedRecords = ListUtils.removeAll(unevaluatedPrivateRecords,
                        authorizedRecords);

                if (!unauthorizedRecords.isEmpty()) {
                    // Create a new query which will exclude unauthorized records
                    BooleanQuery authorizedRecordQuery = new BooleanQuery(true);
                    authorizedRecordQuery.add(query, BooleanClause.Occur.MUST);
                    for (Record unauthorizedRecord : unauthorizedRecords) {
                        TermQuery unauthorizedRecordTQ = new TermQuery(
                                new Term(IndexField.RECORD_ID_FIELD, "" + unauthorizedRecord.getId()));
                        authorizedRecordQuery.add(unauthorizedRecordTQ, BooleanClause.Occur.MUST_NOT);
                    }
                    rb.setQuery(authorizedRecordQuery);
                }
            }
        }
    } else {
        BooleanQuery publicRecordQuery = new BooleanQuery(true);
        publicRecordQuery.add(query, BooleanClause.Occur.MUST);
        TermQuery publicRecordTQ = new TermQuery(new Term(IndexField.PUBLIC_RECORD_FIELD, "T"));
        publicRecordQuery.add(publicRecordTQ, BooleanClause.Occur.MUST);
        for (TermQuery restrictionCollectionQuery : restrictedCollectionQueries) {
            publicRecordQuery.add(restrictionCollectionQuery, BooleanClause.Occur.MUST_NOT);
        }
        rb.setQuery(publicRecordQuery);
    }
}

From source file:com.indoqa.solr.spatial.clustering.SpatialClusteringComponent.java

License:Apache License

private DblClusters<Document> createDocumentClusters(ResponseBuilder rb, int maxCount, Set<String> fields)
        throws IOException {
    DblClusters<Document> clusters = new DblClusters<>(2, maxCount);

    DocSet docSet = rb.getResults().docSet;
    DocIterator iterator = docSet.iterator();

    while (iterator.hasNext()) {
        Integer docId = iterator.next();
        Document doc = rb.req.getSearcher().doc(docId, fields);

        IndexableField latitudeField = doc.getField(this.fieldNameLat);
        IndexableField longitudeField = doc.getField(this.fieldNameLon);

        if (latitudeField == null || longitudeField == null) {
            continue;
        }//  w  w w .j  a v a  2s .c o  m

        String latitudeString = latitudeField.stringValue();
        String longitudeString = longitudeField.stringValue();

        if (!isNumeric(latitudeString) || !isNumeric(longitudeString)) {
            continue;
        }

        clusters.add(1, new double[] { Double.valueOf(latitudeString), Double.valueOf(longitudeString) }, doc);
    }
    return clusters;
}

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

public NodeReport checkNodeCommon(NodeReport nodeReport) {
    long dbid = nodeReport.getDbid();
    RefCounted<SolrIndexSearcher> refCounted = null;

    try {/* www. j a v a2 s  .  co  m*/
        refCounted = core.getSearcher(false, true, null);
        if (refCounted == null) {
            return nodeReport;
        }

        try {
            SolrIndexSearcher solrIndexSearcher = refCounted.get();

            String dbidString = NumericEncoder.encode(dbid);
            DocSet docSet = solrIndexSearcher.getDocSet(new TermQuery(new Term("DBID", dbidString)));
            // should find leaf and aux
            for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) {
                int doc = it.nextDoc();
                Document document = solrIndexSearcher.doc(doc);
                Fieldable fieldable = document.getFieldable("ID");
                if (fieldable != null) {
                    String value = fieldable.stringValue();
                    if (value != null) {
                        if (value.startsWith("LEAF-")) {
                            nodeReport.setIndexLeafDoc(Long.valueOf(doc));
                        } else if (value.startsWith("AUX-")) {
                            nodeReport.setIndexAuxDoc(Long.valueOf(doc));
                        }
                    }
                }
            }

            DocSet txDocSet = solrIndexSearcher.getDocSet(new WildcardQuery(new Term("TXID", "*")));
            for (DocIterator it = txDocSet.iterator(); it.hasNext(); /* */) {
                int doc = it.nextDoc();
                Document document = solrIndexSearcher.doc(doc);
                Fieldable fieldable = document.getFieldable("TXID");
                if (fieldable != null) {

                    if ((nodeReport.getIndexLeafDoc() == null)
                            || (doc < nodeReport.getIndexLeafDoc().longValue())) {
                        String value = fieldable.stringValue();
                        long txid = Long.parseLong(value);
                        nodeReport.setIndexLeafTx(txid);
                    }
                    if ((nodeReport.getIndexAuxDoc() == null)
                            || (doc < nodeReport.getIndexAuxDoc().longValue())) {
                        String value = fieldable.stringValue();
                        long txid = Long.parseLong(value);
                        nodeReport.setIndexAuxTx(txid);
                    }
                }
            }
        } finally {
            refCounted.decref();
        }
    } catch (IOException e) {
        // TODO: do what here?
    }

    return nodeReport;
}

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

private void doUpdateDescendantAuxDocs(NodeMetaData parentNodeMetaData, boolean overwrite,
        SolrIndexSearcher solrIndexSearcher, LinkedHashSet<Long> stack, DocSet skippingDocs)
        throws AuthenticationException, IOException, JSONException {
    if ((skipDescendantAuxDocsForSpecificTypes
            && typesForSkippingDescendantAuxDocs.contains(parentNodeMetaData.getType()))
            || (skipDescendantAuxDocsForSpecificAspects
                    && shouldBeIgnoredByAnyAspect(parentNodeMetaData.getAspects()))) {
        return;/*from   www  .j a v  a  2  s .c om*/
    }

    HashSet<Long> childIds = new HashSet<Long>();

    if (parentNodeMetaData.getChildIds() != null) {
        childIds.addAll(parentNodeMetaData.getChildIds());
    }

    BooleanQuery bQuery = new BooleanQuery();
    bQuery.add(new TermQuery(new Term(QueryConstants.FIELD_PARENT, parentNodeMetaData.getNodeRef().toString())),
            Occur.MUST);
    DocSet docSet = solrIndexSearcher.getDocSet(bQuery);
    ResizeableArrayList<CacheEntry> indexedByDocId = (ResizeableArrayList<CacheEntry>) solrIndexSearcher
            .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE,
                    AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_DOC_ID);
    if (docSet instanceof BitDocSet) {
        BitDocSet source = (BitDocSet) docSet;
        OpenBitSet openBitSet = source.getBits();
        int current = -1;
        while ((current = openBitSet.nextSetBit(current + 1)) != -1) {
            if (!skippingDocs.exists(current)) {
                CacheEntry entry = indexedByDocId.get(current);
                childIds.add(entry.getDbid());
            }
        }
    } else {
        for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) {
            int current = it.nextDoc();
            if (!skippingDocs.exists(current)) {
                CacheEntry entry = indexedByDocId.get(current);
                childIds.add(entry.getDbid());
            }
        }
    }

    for (Long childId : childIds) {
        if (!shouldElementBeIgnored(childId, solrIndexSearcher, skippingDocs)) {
            NodeMetaDataParameters nmdp = new NodeMetaDataParameters();
            nmdp.setFromNodeId(childId);
            nmdp.setToNodeId(childId);
            nmdp.setIncludeAclId(true);
            nmdp.setIncludeAspects(true);
            nmdp.setIncludeChildAssociations(false);
            nmdp.setIncludeChildIds(true);
            nmdp.setIncludeNodeRef(true);
            nmdp.setIncludeOwner(true);
            nmdp.setIncludeParentAssociations(true);
            nmdp.setIncludePaths(true);
            nmdp.setIncludeProperties(false);
            nmdp.setIncludeType(true);
            nmdp.setIncludeTxnId(true);
            // call back to core tracker to talk to client
            List<NodeMetaData> nodeMetaDatas = coreTracker.getNodesMetaData(nmdp, MAX_RESULTS_NODES_META_DATA);

            for (NodeMetaData nodeMetaData : nodeMetaDatas) {
                if (mayHaveChildren(nodeMetaData)) {
                    updateDescendantAuxDocs(nodeMetaData, overwrite, solrIndexSearcher, stack, skippingDocs);
                }

                // Avoid adding aux docs for stuff yet to be indexed or unindexed (via the index control aspect)
                log.info(".. checking aux doc exists in index before we update it");
                Query query = new TermQuery(new Term(QueryConstants.FIELD_ID, "AUX-" + childId));
                DocSet auxSet = solrIndexSearcher.getDocSet(query);
                if (auxSet.size() > 0) {
                    log.debug("... cascade update aux doc " + childId);

                    SolrInputDocument aux = createAuxDoc(nodeMetaData);
                    AddUpdateCommand auxDocCmd = new AddUpdateCommand();
                    auxDocCmd.overwriteCommitted = overwrite;
                    auxDocCmd.overwritePending = overwrite;
                    auxDocCmd.solrDoc = aux;
                    auxDocCmd.doc = toDocument(auxDocCmd.getSolrInputDocument(), core.getSchema(), dataModel);

                    core.getUpdateHandler().addDoc(auxDocCmd);
                } else {
                    log.debug("... no aux doc found to update " + childId);
                }
            }
        }
    }
}

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

private boolean shouldElementBeIgnored(long dbId, SolrIndexSearcher solrIndexSearcher, DocSet skippingDocs)
        throws IOException {
    boolean result = false;

    if ((skipDescendantAuxDocsForSpecificTypes && !typesForSkippingDescendantAuxDocs.isEmpty())
            || (skipDescendantAuxDocsForSpecificAspects && !aspectsForSkippingDescendantAuxDocs.isEmpty())) {
        BooleanQuery query = new BooleanQuery();
        query.add(new TermQuery(new Term(QueryConstants.FIELD_DBID, NumericEncoder.encode(dbId))), Occur.MUST);

        DocSet docSet = solrIndexSearcher.getDocSet(query);

        int index = -1;
        if (docSet instanceof BitDocSet) {
            BitDocSet source = (BitDocSet) docSet;
            OpenBitSet openBitSet = source.getBits();
            index = openBitSet.nextSetBit(index + 1);
        } else {//from  w w w .  ja va2 s.  com
            DocIterator it = docSet.iterator();
            if (it.hasNext()) {
                index = it.nextDoc();
            }
        }

        result = (-1 != index) && skippingDocs.exists(index);
    }

    return result;
}

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

private void deleteByQuery(SolrIndexSearcher solrIndexSearcher, Query query) throws IOException {
    HashSet<String> idsToDelete = new HashSet<String>();

    DocSet docSet = solrIndexSearcher.getDocSet(query);
    if (docSet instanceof BitDocSet) {
        BitDocSet source = (BitDocSet) docSet;
        OpenBitSet openBitSet = source.getBits();
        int current = -1;
        while ((current = openBitSet.nextSetBit(current + 1)) != -1) {
            Document doc = solrIndexSearcher.doc(current, Collections.singleton(QueryConstants.FIELD_ID));
            Fieldable fieldable = doc.getFieldable(QueryConstants.FIELD_ID);
            if (fieldable != null) {
                idsToDelete.add(fieldable.stringValue());
            }//from  w w  w .  ja  v  a 2s .  c o  m

        }
    } else {
        for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) {
            Document doc = solrIndexSearcher.doc(it.nextDoc(), Collections.singleton(QueryConstants.FIELD_ID));
            Fieldable fieldable = doc.getFieldable(QueryConstants.FIELD_ID);
            if (fieldable != null) {
                idsToDelete.add(fieldable.stringValue());
            }
        }
    }

    for (String idToDelete : idsToDelete) {
        DeleteUpdateCommand docCmd = new DeleteUpdateCommand();
        docCmd.id = idToDelete;
        docCmd.fromPending = true;
        docCmd.fromCommitted = true;
        core.getUpdateHandler().delete(docCmd);
    }

}

From source file:org.alfresco.solr.LegacySolrInformationServer.java

License:Open Source License

@Override
public AclReport checkAclInIndex(Long aclid, AclReport aclReport) {
    try {/* ww w  .  ja va2  s.  c o  m*/
        RefCounted<SolrIndexSearcher> refCounted = core.getSearcher(false, true, null);

        refCounted = core.getSearcher(false, true, null);
        if (refCounted == null) {
            return aclReport;
        }

        try {
            SolrIndexSearcher solrIndexSearcher = refCounted.get();
            SolrIndexReader reader = solrIndexSearcher.getReader();

            String aclIdString = NumericEncoder.encode(aclid);
            DocSet docSet = solrIndexSearcher.getDocSet(new TermQuery(new Term("ACLID", aclIdString)));
            // should find leaf and aux
            for (DocIterator it = docSet.iterator(); it.hasNext(); /* */) {
                int doc = it.nextDoc();

                Document document = solrIndexSearcher.doc(doc);
                Fieldable fieldable = document.getFieldable("ID");
                if (fieldable != null) {
                    String value = fieldable.stringValue();
                    if (value != null) {
                        if (value.startsWith("ACL-")) {
                            aclReport.setIndexAclDoc(Long.valueOf(doc));
                        }
                    }
                }

            }
            DocSet txDocSet = solrIndexSearcher.getDocSet(new WildcardQuery(new Term("ACLTXID", "*")));
            for (DocIterator it = txDocSet.iterator(); it.hasNext(); /* */) {
                int doc = it.nextDoc();
                Document document = solrIndexSearcher.doc(doc);
                Fieldable fieldable = document.getFieldable("ACLTXID");
                if (fieldable != null) {

                    if ((aclReport.getIndexAclDoc() == null)
                            || (doc < aclReport.getIndexAclDoc().longValue())) {
                        String value = fieldable.stringValue();
                        long acltxid = Long.parseLong(value);
                        aclReport.setIndexAclTx(acltxid);
                    }

                }
            }

        } finally {
            refCounted.decref();
        }

    } catch (IOException e) {

    }

    return aclReport;
}

From source file:org.alfresco.solr.query.AbstractAuthoritySetQuery.java

License:Open Source License

protected HybridBitSet getACLSet(String[] auths, String field, SolrIndexSearcher searcher) throws IOException {
    /*//from w w  w  . j a va  2  s. c  o  m
    * Build a query that matches the authorities with a field in the ACL records in the index.
    */

    BooleanQuery.Builder queryBuilder = new BooleanQuery.Builder();
    for (String current : auths) {
        queryBuilder.add(new TermQuery(new Term(field, current)), BooleanClause.Occur.SHOULD);
    }

    /*
    *   Collect a docset containing the ACL records that match the query.
    *   This query will be in the filter cache. Ideally it would remain cached throughout the users session.
    */

    DocSet docSet = searcher.getDocSet(queryBuilder.build());

    DocIterator iterator = docSet.iterator();
    if (!iterator.hasNext()) {
        return new EmptyHybridBitSet();
    }

    //TODO : makes this configurable. For some systems this is huge and for others not big enough.
    HybridBitSet hybridBitSet = new HybridBitSet(60000000);

    /*
    * Collect the ACLID's from the matching acl records.
    * This is done in a separate step so the initial ACL query can be cached in the FilterCache
    * The initial ACL query may be expensive if the number of authorities is very large.
    */

    List<LeafReaderContext> leaves = searcher.getTopReaderContext().leaves();
    LeafReaderContext context = leaves.get(0);
    NumericDocValues aclValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID,
            context.reader());
    LeafReader reader = context.reader();
    int ceil = reader.maxDoc();
    int base = 0;
    int ord = 0;
    while (iterator.hasNext()) {
        int doc = iterator.nextDoc();
        if (doc >= ceil) {
            do {
                ++ord;
                context = leaves.get(ord);
                reader = context.reader();
                base = context.docBase;
                ceil = base + reader.maxDoc();
                aclValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID, reader);
            } while (doc >= ceil);
        }

        if (aclValues != null) {
            long aclId = aclValues.get(doc - base);
            hybridBitSet.set(aclId);
        }
    }

    return hybridBitSet;
}

From source file:org.alfresco.solr.query.SolrCachingAuxDocScorer.java

License:Open Source License

public static SolrCachingAuxDocScorer createAuxDocScorer(SolrIndexSearcher searcher, Similarity similarity,
        Query query, SolrIndexReader reader) throws IOException {
    // Get hold of solr top level searcher
    // Execute query with caching
    // translate reults to leaf docs
    // build ordered doc list

    DocSet auxDocSet = searcher.getDocSet(new ContextAwareQuery(query, null));

    ResizeableArrayList<CacheEntry> indexedByDocId = (ResizeableArrayList<CacheEntry>) searcher.cacheLookup(
            AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE,
            AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_DOC_ID);

    // List<ScoreDoc> auxDocs = pathCollector.getDocs();
    OpenBitSet translated = new OpenBitSet(searcher.getReader().maxDoc());

    if (auxDocSet instanceof BitDocSet) {
        BitDocSet source = (BitDocSet) auxDocSet;
        OpenBitSet openBitSet = source.getBits();
        int current = -1;
        while ((current = openBitSet.nextSetBit(current + 1)) != -1) {
            CacheEntry entry = indexedByDocId.get(current);
            translated.set(entry.getLeaf());
        }//from  w ww. j  av  a2s  . c  o m
    } else {
        for (DocIterator it = auxDocSet.iterator(); it.hasNext(); /* */) {
            CacheEntry entry = indexedByDocId.get(it.nextDoc());
            translated.set(entry.getLeaf());
        }
    }

    return new SolrCachingAuxDocScorer(similarity, new BitDocSet(translated), reader);

}

From source file:org.alfresco.solr.query.SolrCachingReaderScorer.java

License:Open Source License

public static SolrCachingReaderScorer createReaderScorer(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

    long[] aclByDocId = (long[]) searcher.cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE,
            AlfrescoSolrEventListener.KEY_ACL_ID_BY_DOC_ID);
    HashMap<AlfrescoSolrEventListener.AclLookUp, AlfrescoSolrEventListener.AclLookUp> lookups = (HashMap<AlfrescoSolrEventListener.AclLookUp, AlfrescoSolrEventListener.AclLookUp>) searcher
            .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_CACHE, AlfrescoSolrEventListener.KEY_ACL_LOOKUP);
    ResizeableArrayList<AlfrescoSolrEventListener.CacheEntry> aclThenLeafOrderedEntries = (ResizeableArrayList<AlfrescoSolrEventListener.CacheEntry>) searcher
            .cacheLookup(AlfrescoSolrEventListener.ALFRESCO_ARRAYLIST_CACHE,
                    AlfrescoSolrEventListener.KEY_DBID_LEAF_PATH_BY_ACL_ID_THEN_LEAF);

    DocSet aclDocSet;
    if (authority.contains("|")) {
        BooleanQuery bQuery = new BooleanQuery();
        for (String current : authority.split("\\|")) {
            bQuery.add(new TermQuery(new Term("READER", current)), Occur.SHOULD);
        }//from  ww  w.j  ava2 s .com
        aclDocSet = searcher.getDocSet(bQuery);
    } else {
        aclDocSet = searcher.getDocSet(new TermQuery(new Term("READER", authority)));
    }

    BitDocSet readableDocSet = new BitDocSet(new OpenBitSet(searcher.getReader().maxDoc()));

    AlfrescoSolrEventListener.AclLookUp key = new AlfrescoSolrEventListener.AclLookUp(0);

    if (aclDocSet instanceof BitDocSet) {
        BitDocSet source = (BitDocSet) aclDocSet;
        OpenBitSet openBitSet = source.getBits();
        int current = -1;
        while ((current = openBitSet.nextSetBit(current + 1)) != -1) {
            long acl = aclByDocId[current];
            key.setAclid(acl);
            AlfrescoSolrEventListener.AclLookUp value = lookups.get(key);
            if (value != null) {
                for (int i = value.getStart(); i < value.getEnd(); i++) {
                    readableDocSet.add(aclThenLeafOrderedEntries.get(i).getLeaf());
                }
            }
        }
    } else {

        for (DocIterator it = aclDocSet.iterator(); it.hasNext(); /* */) {
            int doc = it.nextDoc();
            long acl = aclByDocId[doc];
            key.setAclid(acl);
            AlfrescoSolrEventListener.AclLookUp value = lookups.get(key);
            if (value != null) {
                for (int i = value.getStart(); i < value.getEnd(); i++) {
                    readableDocSet.add(aclThenLeafOrderedEntries.get(i).getLeaf());
                }
            }
        }
    }
    return new SolrCachingReaderScorer(similarity, readableDocSet, reader);

}