internal LuceneIndexStatistics GetStatistics()
        {
            try
            {
                EnsureInitialized();
            }
            catch (Exception e)
            {
                Log.WarnFormat("IDX[{0}] Error during index initialization: {1}", _id, e.Message);
            }

            var result = new LuceneIndexStatistics();

            FillHealthStatus(result);
            FillStatistics(result);
            return(result);
        }
        private void FillStatistics(LuceneIndexStatistics statistics)
        {
            statistics.InitializationTimeUtc = InitializationTimeUtc;
            statistics.LastReopenTimeUtc     = LastReopenTimeUtc;
            statistics.TimesSearcherAcquiredAfterInitialization = _timesSearcherAcquired;
            statistics.TimesWriterAcquiredAfterInitialization   = _timesWriterAcquired;
            statistics.TimesCommittedAfterInitialization        = _timesCommitted;
            statistics.TimesOptimizedAfterInitialization        = _timesOptimized;
            statistics.TimesReopenedAfterInitialization         = _timesReopened;

            statistics.CurrentSearcherRefCount   = _searcherRefCount;
            statistics.CurrentWriterRefCount     = _writerRefCount;
            statistics.CurrentOutstandingChanges = _outstandingChanges;

            bool fileStatisticsExtracted = false;

            if (_initialized && !_shutDown)
            {
                try
                {
                    statistics.FileSizes              = _indexDirectory.ListAll().ToDictionary(s => s, s => _indexDirectory.FileLength(s));
                    statistics.TotalSizeBytes         = statistics.FileSizes.Values.Sum();
                    statistics.TotalNumberOfDocuments = _indexWriter.MaxDoc();

                    fileStatisticsExtracted = true;
                }
                catch (Exception e)
                {
                    Log.Error("IDX[" + _id + "] Error while extracting file statistics: {1}", e);
                }
            }

            if (!fileStatisticsExtracted)
            {
                // Make sure the FileSizes is not null in the result
                statistics.FileSizes = new Dictionary <string, long>();
            }
        }