Wrap() public static method

Convenience wrapper method: If {@code acceptDocs == null} it returns the original set without wrapping.
public static Wrap ( Lucene.Net.Search.DocIdSet set, Lucene.Net.Util.Bits acceptDocs ) : Lucene.Net.Search.DocIdSet
set Lucene.Net.Search.DocIdSet Underlying DocIdSet. If {@code null}, this method returns {@code null}
acceptDocs Lucene.Net.Util.Bits Allowed docs, all docids not in this set will not be returned by this DocIdSet. /// If {@code null}, this method returns the original set without wrapping.
return Lucene.Net.Search.DocIdSet
Ejemplo n.º 1
0
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            var    reader = context.AtomicReader;
            object key    = reader.CoreCacheKey;

            if (_cache.TryGetValue(key, out DocIdSet docIdSet) && docIdSet != null)
            {
                hitCount++;
            }
            else
            {
                missCount++;
                docIdSet = DocIdSetToCache(_filter.GetDocIdSet(context, null), reader);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(docIdSet.IsCacheable);
                }
#if FEATURE_CONDITIONALWEAKTABLE_ADDORUPDATE
                _cache.AddOrUpdate(key, docIdSet);
#else
                _cache[key] = docIdSet;
#endif
            }

            return(docIdSet == EMPTY_DOCIDSET ? null : BitsFilteredDocIdSet.Wrap(docIdSet, acceptDocs));
        }
Ejemplo n.º 2
0
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            IBits docsWithField = FieldCache.DEFAULT.GetDocsWithField(((AtomicReader)context.Reader), field);

            if (negate)
            {
                if (docsWithField is MatchAllBits)
                {
                    return(null);
                }
                return(new FieldCacheDocIdSetAnonymousInnerClassHelper(this, context.AtomicReader.MaxDoc, acceptDocs, docsWithField));
            }
            else
            {
                if (docsWithField is MatchNoBits)
                {
                    return(null);
                }
                if (docsWithField is DocIdSet)
                {
                    // UweSays: this is always the case for our current impl - but who knows
                    // :-)
                    return(BitsFilteredDocIdSet.Wrap((DocIdSet)docsWithField, acceptDocs));
                }
                return(new FieldCacheDocIdSetAnonymousInnerClassHelper2(this, context.AtomicReader.MaxDoc, acceptDocs, docsWithField));
            }
        }
Ejemplo n.º 3
0
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            var    reader = context.AtomicReader;
            object key    = reader.CoreCacheKey;

            DocIdSet docIdSet = _cache[key];

            if (docIdSet != null)
            {
                hitCount++;
            }
            else
            {
                missCount++;
                docIdSet = DocIdSetToCache(_filter.GetDocIdSet(context, null), reader);
                Debug.Assert(docIdSet.IsCacheable);
                _cache[key] = docIdSet;
            }

            return(docIdSet == EMPTY_DOCIDSET ? null : BitsFilteredDocIdSet.Wrap(docIdSet, acceptDocs));
        }
Ejemplo n.º 4
0
        public override DocIdSet GetDocIdSet(AtomicReaderContext context, IBits acceptDocs)
        {
            var    reader = context.AtomicReader;
            object key    = reader.CoreCacheKey;

            if (cache.TryGetValue(key, out DocIdSet docIdSet))
            {
                hitCount++;
            }
            else
            {
                missCount++;
                docIdSet = DocIdSetToCache(filter.GetDocIdSet(context, null), reader);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(docIdSet.IsCacheable);
                }
#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
                cache.AddOrUpdate(key, docIdSet);
#else
                UninterruptableMonitor.Enter(cache);
                try
                {
                    cache.AddOrUpdate(key, docIdSet);
                    // LUCENENET specific - since .NET Standard 2.0 and .NET Framework don't have a CondtionalWeakTable enumerator,
                    // we use a weak event to retrieve the DocIdSet instances
                    reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent <Events.GetCacheKeysEvent>());
                }
                finally
                {
                    UninterruptableMonitor.Exit(cache);
                }
#endif
            }

            return(docIdSet == EMPTY_DOCIDSET ? null : BitsFilteredDocIdSet.Wrap(docIdSet, acceptDocs));
        }