protected void UpdateIndexingStats(WorkContext context, IndexingWorkStats stats) { }
protected void Write(WorkContext context, Func <IndexWriter, Analyzer, IndexingWorkStats, int> action) { if (disposed) { throw new ObjectDisposedException("Index " + name + " has been disposed"); } LastIndexTime = DateTime.UtcNow; lock (writeLock) { bool shouldRecreateSearcher; var toDispose = new List <Action>(); Analyzer searchAnalyzer = null; try { waitReason = "Write"; try { searchAnalyzer = CreateAnalyzer(new LowerCaseKeywordAnalyzer(), toDispose); } catch (Exception e) { //context.AddError(name, "Creating Analyzer", e.ToString()); throw; } if (indexWriter == null) { indexWriter = CreateIndexWriter(directory); } var locker = directory.MakeLock("writing-to-index.lock"); try { var stats = new IndexingWorkStats(); try { var changedDocs = action(indexWriter, searchAnalyzer, stats); docCountSinceLastOptimization += changedDocs; shouldRecreateSearcher = changedDocs > 0; //foreach (IIndexExtension indexExtension in indexExtensions.Values) //{ // indexExtension.OnDocumentsIndexed(currentlyIndexDocuments); //} } catch (Exception e) { //context.AddError(name, null, e.ToString()); throw; } UpdateIndexingStats(context, stats); Flush(); // just make sure changes are flushed to disk } finally { locker.Release(); } } finally { //currentlyIndexDocuments.Clear(); if (searchAnalyzer != null) { searchAnalyzer.Close(); } foreach (Action dispose in toDispose) { dispose(); } waitReason = null; LastIndexTime = DateTime.UtcNow; } if (shouldRecreateSearcher) { RecreateSearcher(); } } }