Search in sources :

Example 1 with BitDocSet

use of org.apache.solr.search.BitDocSet in project lucene-solr by apache.

the class FacetProcessor method handleBlockJoin.

// returns "true" if filters were applied to fcontext.base already
private boolean handleBlockJoin() throws IOException {
    boolean appliedFilters = false;
    if (!(freq.domain.toChildren || freq.domain.toParent))
        return appliedFilters;
    // TODO: avoid query parsing per-bucket somehow...
    String parentStr = freq.domain.parents;
    Query parentQuery;
    try {
        QParser parser = QParser.getParser(parentStr, fcontext.req);
        parser.setIsFilter(true);
        parentQuery = parser.getQuery();
    } catch (SyntaxError err) {
        throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, "Error parsing block join parent specification: " + parentStr);
    }
    BitDocSet parents = fcontext.searcher.getDocSetBits(parentQuery);
    DocSet input = fcontext.base;
    DocSet result;
    if (freq.domain.toChildren) {
        // If there are filters on this facet, then use them as acceptDocs when executing toChildren.
        // We need to remember to not redundantly re-apply these filters after.
        DocSet acceptDocs = this.filter;
        if (acceptDocs == null) {
            acceptDocs = fcontext.searcher.getLiveDocs();
        } else {
            appliedFilters = true;
        }
        result = BlockJoin.toChildren(input, parents, acceptDocs, fcontext.qcontext);
    } else {
        result = BlockJoin.toParents(input, parents, fcontext.qcontext);
    }
    fcontext.base = result;
    return appliedFilters;
}
Also used : BitDocSet(org.apache.solr.search.BitDocSet) Query(org.apache.lucene.search.Query) BooleanQuery(org.apache.lucene.search.BooleanQuery) SyntaxError(org.apache.solr.search.SyntaxError) QParser(org.apache.solr.search.QParser) SolrException(org.apache.solr.common.SolrException) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Example 2 with BitDocSet

use of org.apache.solr.search.BitDocSet in project lucene-solr by apache.

the class UnInvertedField method getCounts.

private void getCounts(FacetFieldProcessorByArrayUIF processor, CountSlotAcc counts) throws IOException {
    DocSet docs = processor.fcontext.base;
    int baseSize = docs.size();
    int maxDoc = searcher.maxDoc();
    // what about allBuckets?
    if (baseSize < processor.effectiveMincount) {
        return;
    }
    final int[] index = this.index;
    boolean doNegative = baseSize > maxDoc >> 1 && termInstances > 0 && docs instanceof BitDocSet;
    if (doNegative) {
        FixedBitSet bs = ((BitDocSet) docs).getBits().clone();
        bs.flip(0, maxDoc);
        // TODO: when iterator across negative elements is available, use that
        // instead of creating a new bitset and inverting.
        docs = new BitDocSet(bs, maxDoc - baseSize);
    // simply negating will mean that we have deleted docs in the set.
    // that should be OK, as their entries in our table should be empty.
    }
    // For the biggest terms, do straight set intersections
    for (TopTerm tt : bigTerms.values()) {
        // TODO: counts could be deferred if sorting by index order
        counts.incrementCount(tt.termNum, searcher.numDocs(tt.termQuery, docs));
    }
    if (termInstances > 0) {
        DocIterator iter = docs.iterator();
        while (iter.hasNext()) {
            int doc = iter.nextDoc();
            int code = index[doc];
            if ((code & 0xff) == 1) {
                int pos = code >>> 8;
                int whichArray = (doc >>> 16) & 0xff;
                byte[] arr = tnums[whichArray];
                int tnum = 0;
                for (; ; ) {
                    int delta = 0;
                    for (; ; ) {
                        byte b = arr[pos++];
                        delta = (delta << 7) | (b & 0x7f);
                        if ((b & 0x80) == 0)
                            break;
                    }
                    if (delta == 0)
                        break;
                    tnum += delta - TNUM_OFFSET;
                    counts.incrementCount(tnum, 1);
                }
            } else {
                int tnum = 0;
                int delta = 0;
                for (; ; ) {
                    delta = (delta << 7) | (code & 0x7f);
                    if ((code & 0x80) == 0) {
                        if (delta == 0)
                            break;
                        tnum += delta - TNUM_OFFSET;
                        counts.incrementCount(tnum, 1);
                        delta = 0;
                    }
                    code >>>= 8;
                }
            }
        }
    }
    if (doNegative) {
        for (int i = 0; i < numTermsInField; i++) {
            //       counts[i] = maxTermCounts[i] - counts[i];
            counts.incrementCount(i, maxTermCounts[i] - counts.getCount(i) * 2);
        }
    }
/*** TODO - future optimization to handle allBuckets
    if (processor.allBucketsSlot >= 0) {
      int all = 0;  // overflow potential
      for (int i=0; i<numTermsInField; i++) {
        all += counts.getCount(i);
      }
      counts.incrementCount(processor.allBucketsSlot, all);
    }
     ***/
}
Also used : BitDocSet(org.apache.solr.search.BitDocSet) DocIterator(org.apache.solr.search.DocIterator) FixedBitSet(org.apache.lucene.util.FixedBitSet) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Example 3 with BitDocSet

use of org.apache.solr.search.BitDocSet in project SearchServices by Alfresco.

the class SolrDeniedScorer method createDenyScorer.

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);
            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);
}
Also used : SchemaField(org.apache.solr.schema.SchemaField) TermQuery(org.apache.lucene.search.TermQuery) BitDocSet(org.apache.solr.search.BitDocSet) DocIterator(org.apache.solr.search.DocIterator) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) FixedBitSet(org.apache.lucene.util.FixedBitSet) Term(org.apache.lucene.index.Term) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Example 4 with BitDocSet

use of org.apache.solr.search.BitDocSet in project SearchServices by Alfresco.

the class SolrReaderSetScorer method createReaderSetScorer.

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);
        }
        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);
    }
    // plus check of course, for presence in cache at start of method.
    return new SolrReaderSetScorer(weight, readableDocSet, context, searcher);
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) DocIterator(org.apache.solr.search.DocIterator) Query(org.apache.lucene.search.Query) TermQuery(org.apache.lucene.search.TermQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) Term(org.apache.lucene.index.Term) SchemaField(org.apache.solr.schema.SchemaField) BitDocSet(org.apache.solr.search.BitDocSet) FixedBitSet(org.apache.lucene.util.FixedBitSet) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet)

Example 5 with BitDocSet

use of org.apache.solr.search.BitDocSet in project SearchServices by Alfresco.

the class SolrDenySetScorer2 method createDenySetScorer.

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);
        }
        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);
    }
    // plus check of course, for presence in cache at start of method.
    return new SolrDenySetScorer2(weight, deniedDocSet, context, searcher);
}
Also used : BooleanQuery(org.apache.lucene.search.BooleanQuery) TermQuery(org.apache.lucene.search.TermQuery) NumericDocValues(org.apache.lucene.index.NumericDocValues) DocIterator(org.apache.solr.search.DocIterator) WrappedQuery(org.apache.solr.search.WrappedQuery) Term(org.apache.lucene.index.Term) BitDocSet(org.apache.solr.search.BitDocSet) FixedBitSet(org.apache.lucene.util.FixedBitSet) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) BitDocSet(org.apache.solr.search.BitDocSet) DocSet(org.apache.solr.search.DocSet) HashSet(java.util.HashSet)

Aggregations

BitDocSet (org.apache.solr.search.BitDocSet)13 DocSet (org.apache.solr.search.DocSet)12 FixedBitSet (org.apache.lucene.util.FixedBitSet)9 Term (org.apache.lucene.index.Term)7 TermQuery (org.apache.lucene.search.TermQuery)7 DocIterator (org.apache.solr.search.DocIterator)7 BooleanQuery (org.apache.lucene.search.BooleanQuery)6 Query (org.apache.lucene.search.Query)6 SchemaField (org.apache.solr.schema.SchemaField)5 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)4 HashSet (java.util.HashSet)2 NumericDocValues (org.apache.lucene.index.NumericDocValues)2 AllGroupHeadsCollector (org.apache.lucene.search.grouping.AllGroupHeadsCollector)2 QParser (org.apache.solr.search.QParser)2 WrappedQuery (org.apache.solr.search.WrappedQuery)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 IdentityHashMap (java.util.IdentityHashMap)1 Map (java.util.Map)1