コード例 #1
0
        public IndexWriteOperation(Index index, LuceneVoronDirectory directory, LuceneDocumentConverterBase converter, Transaction writeTransaction, LuceneIndexPersistence persistence)
            : base(index, LoggingSource.Instance.GetLogger <IndexWriteOperation>(index._indexStorage.DocumentDatabase.Name))
        {
            _converter       = converter;
            DocumentDatabase = index._indexStorage.DocumentDatabase;

            try
            {
                _analyzer = CreateAnalyzer(() => new LowerCaseKeywordAnalyzer(), index.Definition.IndexFields);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            try
            {
                _releaseWriteTransaction = directory.SetTransaction(writeTransaction, out _state);
                _writer = persistence.EnsureIndexWriter(_state);

                _suggestionsWriters = persistence.EnsureSuggestionIndexWriter(_state);
                _hasSuggestions     = _suggestionsWriters.Count > 0;

                _locker = directory.MakeLock("writing-to-index.lock");

                if (_locker.Obtain() == false)
                {
                    throw new InvalidOperationException($"Could not obtain the 'writing-to-index' lock for '{_indexName}' index.");
                }
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }
コード例 #2
0
        public IndexWriteOperation(string indexName, Dictionary <string, IndexField> fields,
                                   LuceneVoronDirectory directory, LuceneDocumentConverterBase converter,
                                   Transaction writeTransaction, LuceneIndexPersistence persistence, DocumentDatabase documentDatabase)
            : base(indexName, LoggingSource.Instance.GetLogger <IndexWriteOperation>(documentDatabase.Name))
        {
            _converter = converter;
            try
            {
                _analyzer = CreateAnalyzer(() => new LowerCaseKeywordAnalyzer(), fields);
            }
            catch (Exception e)
            {
                throw new IndexAnalyzerException(e);
            }

            try
            {
                _releaseWriteTransaction = directory.SetTransaction(writeTransaction);

                _writer = persistence.EnsureIndexWriter();

                _locker = directory.MakeLock("writing-to-index.lock");

                if (_locker.Obtain() == false)
                {
                    throw new InvalidOperationException($"Could not obtain the 'writing-to-index' lock for '{_indexName}' index.");
                }
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }
コード例 #3
0
        public void Commit(IState state)
        {
            try
            {
                _indexWriter.Commit(state);
            }
            catch (SystemException e)
            {
                LuceneIndexWriter.TryThrowingBetterException(e, _directory);

                throw;
            }
        }
コード例 #4
0
        public void DisposeWriters()
        {
            _indexWriter?.Analyzer?.Dispose();
            _indexWriter?.Dispose();
            _indexWriter = null;

            if (_suggestionsIndexWriters != null)
            {
                foreach (var writer in _suggestionsIndexWriters)
                {
                    writer.Value?.Dispose();
                }

                _suggestionsIndexWriters = null;
            }
        }
コード例 #5
0
        public void Optimize(IState state)
        {
            try
            {
                _indexWriter.Optimize(state);
            }
            catch (SystemException e)
            {
                LuceneIndexWriter.TryThrowingBetterException(e, _directory);

                throw;
            }
            finally
            {
                RecreateIndexWriter(state);
            }
        }
コード例 #6
0
        internal LuceneIndexWriter EnsureIndexWriter(IState state)
        {
            if (_indexWriter != null)
            {
                return(_indexWriter);
            }

            try
            {
                _snapshotter = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
                return(_indexWriter = new LuceneIndexWriter(_directory, StopAnalyzer, _snapshotter,
                                                            IndexWriter.MaxFieldLength.UNLIMITED, null, _index._indexStorage.DocumentDatabase, state));
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }
コード例 #7
0
        public void Commit(IState state)
        {
            try
            {
                _indexWriter.Commit(state);
            }
            catch (SystemException e)
            {
                LuceneIndexWriter.TryThrowingBetterException(e, _directory);

                throw;
            }
            finally
            {
                _indexSearcher?.Dispose();
                _indexSearcher = null;
            }
        }
コード例 #8
0
        internal LuceneIndexWriter EnsureIndexWriter()
        {
            if (_indexWriter != null)
            {
                return(_indexWriter);
            }

            try
            {
                _snapshotter = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
                // TODO [ppekrol] support for IndexReaderWarmer?
                return(_indexWriter = new LuceneIndexWriter(_directory, StopAnalyzer, _snapshotter,
                                                            IndexWriter.MaxFieldLength.UNLIMITED, null, _index._indexStorage.DocumentDatabase));
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }
コード例 #9
0
        internal LuceneIndexWriter EnsureIndexWriter(IState state)
        {
            if (_indexWriter != null)
            {
                return(_indexWriter);
            }

            try
            {
                _snapshotter = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
                return(_indexWriter = new LuceneIndexWriter(_directory, StopAnalyzer, _snapshotter,
                                                            IndexWriter.MaxFieldLength.UNLIMITED, null, _index, state));
            }
            catch (Exception e) when(e.IsOutOfMemory() || e is DiskFullException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new IndexWriteException(e);
            }
        }