Пример #1
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            object cacheKey = context.Reader.CoreCacheKey;

#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
            return(ordsCache.GetValue(cacheKey, (cacheKey) => new CachedOrds(source.GetReader(context), context.Reader.MaxDoc)));
#else
            CachedOrds ords;
            syncLock.EnterReadLock();
            try
            {
                if (ordsCache.TryGetValue(cacheKey, out ords))
                {
                    return(ords);
                }
            }
            finally
            {
                syncLock.ExitReadLock();
            }

            ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
            syncLock.EnterWriteLock();
            try
            {
                ordsCache[cacheKey] = ords;
            }
            finally
            {
                syncLock.ExitWriteLock();
            }

            return(ords);
#endif
        }
Пример #2
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            // LUCENENET NOTE: Since ConditionalWeakTable doesn't synchronize on enumeration in the RamBytesUsed() method,
            // the lock is still required here despite it being a threadsafe collection.
            UninterruptableMonitor.Enter(syncLock);
            try
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords))
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);

                    // LUCENENET specific: Since this is the only thread that can modify ordsCache
                    // and we just checked that the value doesn't exist above, we can simplify this to Add()
                    // which also means we don't need conditional compilation because ConditionalWeakTable
                    // doesn't support this[index].
                    ordsCache.Add(cacheKey, ords);
                }
                return(ords);
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }
        }
Пример #3
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            // LUCENENET NOTE: Since ConditionalWeakTable doesn't synchronize on enumeration in the RamBytesUsed() method,
            // the lock is still required here despite it being a threadsafe collection.
            UninterruptableMonitor.Enter(syncLock);
            try
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords))
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);

                    // LUCENENET specific: Since this is the only thread that can modify ordsCache
                    // and we just checked that the value doesn't exist above, we can simplify this to Add()
                    // which also means we don't need conditional compilation because ConditionalWeakTable
                    // doesn't support this[index].
                    ordsCache.Add(cacheKey, ords);
#if !FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
                    // LUCENENET specific: Add weak event handler for .NET Standard 2.0 and .NET Framework, since we don't have an enumerator to use
                    context.Reader.SubscribeToGetCacheKeysEvent(eventAggregator.GetEvent <Events.GetCacheKeysEvent>());
#endif
                }
                return(ords);
            }
            finally
            {
                UninterruptableMonitor.Exit(syncLock);
            }
        }
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            object cacheKey = context.Reader.CoreCacheKey;

#if FEATURE_CONDITIONALWEAKTABLE_ENUMERATOR
            return(ordsCache.GetValue(cacheKey, (cacheKey) => new CachedOrds(source.GetReader(context), context.Reader.MaxDoc)));
#else
            lock (this)
            {
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords) || ords == null)
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
                    ordsCache[cacheKey] = ords;
                }

                return(ords);
            }
#endif
        }
Пример #5
0
        private CachedOrds GetCachedOrds(AtomicReaderContext context)
        {
            lock (this)
            {
                object cacheKey = context.Reader.CoreCacheKey;
                if (!ordsCache.TryGetValue(cacheKey, out CachedOrds ords) || ords == null)
                {
                    ords = new CachedOrds(source.GetReader(context), context.Reader.MaxDoc);
                    ordsCache[cacheKey] = ords;
                }

                return(ords);
            }
        }
Пример #6
0
        private void Count(IList <FacetsCollector.MatchingDocs> matchingDocs)
        {
            Int32sRef scratch = new Int32sRef();

            foreach (FacetsCollector.MatchingDocs hits in matchingDocs)
            {
                OrdinalsReader.OrdinalsSegmentReader ords = ordinalsReader.GetReader(hits.Context);
                DocIdSetIterator docs = hits.Bits.GetIterator();

                int doc;
                while ((doc = docs.NextDoc()) != DocIdSetIterator.NO_MORE_DOCS)
                {
                    ords.Get(doc, scratch);
                    for (int i = 0; i < scratch.Length; i++)
                    {
                        m_values[scratch.Int32s[scratch.Offset + i]]++;
                    }
                }
            }

            Rollup();
        }