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

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

Introduction

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

Prototype

public void add(int doc);

Source Link

Document

Adds the specified document if it is not currently in the DocSet (optional operation).

Usage

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

License:Open Source License

public static SolrDenySetScorer2 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);
        }/*from  www. j  a  v a 2  s .  c o m*/
        WrappedQuery wrapped = new WrappedQuery(bQuery.build());
        wrapped.setCache(false);

        DocSet aclDocs = searcher.getDocSet(wrapped);

        HashSet<Long> aclsFound = new HashSet<Long>(aclDocs.size());
        NumericDocValues aclDocValues = searcher.getSlowAtomicReader()
                .getNumericDocValues(QueryConstants.FIELD_ACLID);

        for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) {
            int docID = it.nextDoc();
            // Obtain the ACL ID for this ACL doc.
            long aclID = aclDocValues.get(docID);
            aclsFound.add(getLong(aclID));
        }

        if (aclsFound.size() > 0) {
            for (LeafReaderContext readerContext : searcher.getSlowAtomicReader().leaves()) {
                int maxDoc = readerContext.reader().maxDoc();
                NumericDocValues fieldValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID,
                        readerContext.reader());
                if (fieldValues != null) {
                    for (int i = 0; i < maxDoc; i++) {
                        long aclID = fieldValues.get(i);
                        Long key = getLong(aclID);
                        if (aclsFound.contains(key)) {
                            deniedDocSet.add(readerContext.docBase + i);
                        }
                    }
                }

            }
        }

        // 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 SolrDenySetScorer2(weight, deniedDocSet, context, searcher);

}

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

License:Open Source License

public static AbstractSolrCachingScorer 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);
        }//www  . j av a2s.c o  m
        WrappedQuery wrapped = new WrappedQuery(bQuery.build());
        wrapped.setCache(false);

        DocSet aclDocs = searcher.getDocSet(wrapped);

        HashSet<Long> aclsFound = new HashSet<Long>(aclDocs.size());
        NumericDocValues aclDocValues = searcher.getSlowAtomicReader()
                .getNumericDocValues(QueryConstants.FIELD_ACLID);

        for (DocIterator it = aclDocs.iterator(); it.hasNext(); /**/) {
            int docID = it.nextDoc();
            // Obtain the ACL ID for this ACL doc.
            long aclID = aclDocValues.get(docID);
            aclsFound.add(getLong(aclID));
        }

        if (aclsFound.size() > 0) {
            for (LeafReaderContext readerContext : searcher.getSlowAtomicReader().leaves()) {
                int maxDoc = readerContext.reader().maxDoc();
                NumericDocValues fieldValues = DocValuesCache.getNumericDocValues(QueryConstants.FIELD_ACLID,
                        readerContext.reader());
                if (fieldValues != null) {
                    for (int i = 0; i < maxDoc; i++) {
                        long aclID = fieldValues.get(i);
                        Long key = getLong(aclID);
                        if (aclsFound.contains(key)) {
                            readableDocSet.add(readerContext.docBase + i);
                        }
                    }
                }

            }
        }

        // 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 SolrReaderSetScorer2(weight, readableDocSet, context, searcher);
}