Ejemplo n.º 1
0
        internal static void SaveResultsAndClearLucenePool(string luceneIndex)
        {
            ReadWriteLock.TryEnterWriteLock(IndexConstants.ReadWriteLockTimeOutMilliseconds);

            try
            {
                if (IndexReaderPool.TryRemove(luceneIndex, out var indexReader))
                {
                    indexReader.Dispose();
                }

                if (IndexWritesPool.TryRemove(luceneIndex, out var indexWriter))
                {
                    indexWriter.Dispose();
                }

                IndexSearcherPool.TryRemove(luceneIndex, out _);

                IndexGotChanged.AddOrUpdate(luceneIndex, u => 0, (u, v) => 0);
            }
            finally
            {
                ReadWriteLock.ExitWriteLock();
            }
        }
Ejemplo n.º 2
0
        static IndexReader CreateOrGetIndexReader(string luceneIndex, bool forceRefresh)
        {
            IndexReader indexReader;

            if (!IndexReaderPool.TryGetValue(luceneIndex, out indexReader) || forceRefresh)
            {
                lock (syncLockForReader)
                {
                    if (!IndexReaderPool.TryGetValue(luceneIndex, out indexReader))
                    {
                        indexReader = CreateOrGetIndexWriter(luceneIndex).GetReader(true);
                        IndexReaderPool.TryAdd(luceneIndex, indexReader);
                    }
                    else if (forceRefresh)
                    {
                        indexReader.DecRef(); // Dispose safely
                        indexReader = CreateOrGetIndexWriter(luceneIndex).GetReader(true);
                        IndexReaderPool.AddOrUpdate(luceneIndex, indexReader, (u, v) => indexReader);
                    }
                }
            }

            return(indexReader);
        }