protected override DocIdSet CacheImpl(DocIdSetIterator iterator, AtomicReader reader) { FixedBitSet cached = new FixedBitSet(reader.MaxDoc); cached.Or(iterator); return(cached); }
protected override DocIdSet DocIdSetToCache(DocIdSet docIdSet, AtomicReader reader) { if (docIdSet == null) { return(EMPTY_DOCIDSET); } if (docIdSet is FixedBitSet) { // this is different from CachingWrapperFilter: even when the DocIdSet is // cacheable, we convert it to a FixedBitSet since we require all the // cached filters to be FixedBitSets return(docIdSet); } DocIdSetIterator it = docIdSet.GetIterator(); if (it == null) { return(EMPTY_DOCIDSET); } FixedBitSet copy = new FixedBitSet(reader.MaxDoc); copy.Or(it); return(copy); }
protected override DocIdSet CacheImpl(DocIdSetIterator iterator, AtomicReader reader) { var cached = new FixedBitSet(reader.MaxDoc); filterWasUsed.Set(true); cached.Or(iterator); return(cached); }
private FixedBitSet InitialResult(AtomicReaderContext context, int logic, int[] index) { AtomicReader reader = context.AtomicReader; FixedBitSet result = new FixedBitSet(reader.MaxDoc); if (logic == AND) { result.Or(GetDISI(chain[index[0]], context)); ++index[0]; } else if (logic == ANDNOT) { result.Or(GetDISI(chain[index[0]], context)); result.Flip(0, reader.MaxDoc); // NOTE: may set bits for deleted docs. ++index[0]; } return(result); }
public DocumentFilteredAtomicIndexReader(AtomicReaderContext context, Filter preserveFilter, bool negateFilter) : base(context.AtomicReader) { int maxDoc = m_input.MaxDoc; FixedBitSet bits = new FixedBitSet(maxDoc); // ignore livedocs here, as we filter them later: DocIdSet docs = preserveFilter.GetDocIdSet(context, null); if (docs != null) { DocIdSetIterator it = docs.GetIterator(); if (it != null) { bits.Or(it); } } if (negateFilter) { bits.Flip(0, maxDoc); } if (m_input.HasDeletions) { IBits oldLiveDocs = m_input.LiveDocs; if (Debugging.AssertsEnabled) { Debugging.Assert(oldLiveDocs != null); } DocIdSetIterator it = bits.GetIterator(); for (int i = it.NextDoc(); i < maxDoc; i = it.NextDoc()) { if (!oldLiveDocs.Get(i)) { // we can safely modify the current bit, as the iterator already stepped over it: bits.Clear(i); } } } this.liveDocs = bits; this.numDocs = bits.Cardinality(); }
/// <exception cref="IOException"/> private void DoChain(FixedBitSet result, int logic, DocIdSet dis) { if (dis is FixedBitSet) { // optimized case for FixedBitSets switch (logic) { case OR: result.Or((FixedBitSet)dis); break; case AND: result.And((FixedBitSet)dis); break; case ANDNOT: result.AndNot((FixedBitSet)dis); break; case XOR: result.Xor((FixedBitSet)dis); break; default: DoChain(result, DEFAULT, dis); break; } } else { DocIdSetIterator disi; if (dis == null) { disi = DocIdSetIterator.GetEmpty(); } else { disi = dis.GetIterator() ?? DocIdSetIterator.GetEmpty(); } switch (logic) { case OR: result.Or(disi); break; case AND: result.And(disi); break; case ANDNOT: result.AndNot(disi); break; case XOR: result.Xor(disi); break; default: DoChain(result, DEFAULT, dis); break; } } }
/// <summary> /// Returns the a <see cref="DocIdSetIterator"/> representing the Boolean composition /// of the filters that have been added. /// </summary> public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs) { FixedBitSet res = null; AtomicReader reader = context.AtomicReader; bool hasShouldClauses = false; foreach (FilterClause fc in clauses) { if (fc.Occur == Occur.SHOULD) { hasShouldClauses = true; DocIdSetIterator disi = GetDISI(fc.Filter, context); if (disi == null) { continue; } if (res == null) { res = new FixedBitSet(reader.MaxDoc); } res.Or(disi); } } if (hasShouldClauses && res == null) { return(null); } foreach (FilterClause fc in clauses) { if (fc.Occur == Occur.MUST_NOT) { if (res == null) { Debug.Assert(!hasShouldClauses); res = new FixedBitSet(reader.MaxDoc); res.Set(0, reader.MaxDoc); // NOTE: may set bits on deleted docs } DocIdSetIterator disi = GetDISI(fc.Filter, context); if (disi != null) { res.AndNot(disi); } } } foreach (FilterClause fc in clauses) { if (fc.Occur == Occur.MUST) { DocIdSetIterator disi = GetDISI(fc.Filter, context); if (disi == null) { return(null); // no documents can match } if (res == null) { res = new FixedBitSet(reader.MaxDoc); res.Or(disi); } else { res.And(disi); } } } return(BitsFilteredDocIdSet.Wrap(res, acceptDocs)); }