static private GetDocument ( IndexDocumentData docData ) : Lucene.Net.Documents.Document | ||
docData | IndexDocumentData | |
return | Lucene.Net.Documents.Document |
// caller: IndexPopulator.Populator public void RepopulateTree(string path) { using (var op = SnTrace.Index.StartOperation("IndexPopulator RepopulateTree")) { var writer = IndexManager.GetIndexWriter(false); writer.DeleteDocuments(new Term(LucObject.FieldName.InTree, path.ToLowerInvariant())); try { var excludedNodeTypes = LuceneManager.GetNotIndexedNodeTypes(); foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath(path, excludedNodeTypes)) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } writer.Optimize(); } finally { writer.Close(); } op.Successful = true; } }
// caller: IndexPopulator.Populator public void RepopulateTree(string path) { using (var traceOperation = Logger.TraceOperation("IndexPopulator RepopulateTree")) { var writer = IndexManager.GetIndexWriter(false); writer.DeleteDocuments(new Term(LucObject.FieldName.InTree, path.ToLower())); try { foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath(path)) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } writer.Optimize(); } finally { writer.Close(); } traceOperation.IsSuccessful = true; } }
internal static bool AddTree(string treeRoot, bool moveOrRename, int activityId, bool executingUnprocessedActivities) { if (!IsActivityExecutable(executingUnprocessedActivities)) { SnTrace.Index.Write("LM: AddTree skipped #1. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, TreeRoot:{2}", activityId, executingUnprocessedActivities, treeRoot); return(false); } SnTrace.Index.Write("LM: AddTree. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, TreeRoot:{2}", activityId, executingUnprocessedActivities, treeRoot); using (var wrFrame = IndexWriterFrame.Get(false)) { if (executingUnprocessedActivities) // pessimistic compensation { wrFrame.IndexWriter.DeleteDocuments(new Term("InTree", treeRoot), new Term("Path", treeRoot)); } var excludedNodeTypes = GetNotIndexedNodeTypes(); foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath(treeRoot, excludedNodeTypes)) { Document document; int versionId; try { document = IndexDocumentInfo.GetDocument(docData); if (document == null) // indexing disabled { continue; } versionId = GetVersionIdFromDocument(document); } catch (Exception e) { var path = docData == null ? string.Empty : docData.Path ?? string.Empty; SnLog.WriteException(e, "Error during indexing: the document data loaded from the database or the generated Lucene Document is invalid. Please save the content to regenerate the index for it. Path: " + path); SnTrace.Index.WriteError("LM: Error during indexing: the document data loaded from the database or the generated Lucene Document is invalid. Please save the content to regenerate the index for it. Path: " + path); SnTrace.Index.WriteError("LM: Error during indexing: " + e); throw; } // pessimistic approach: delete document before adding it to avoid duplicate index documents wrFrame.IndexWriter.DeleteDocuments(GetVersionIdTerm(versionId)); wrFrame.IndexWriter.AddDocument(document); } } return(true); }
/*======================================================================================================= IIndexPopulator Members */ // caller: IndexPopulator.Populator, Import.Importer, Tests.Initializer, RunOnce public void ClearAndPopulateAll(bool backup = true) { var lastActivityId = LuceneManager.GetLastStoredIndexingActivityId(); var commitData = CompletionState.GetCommitUserData(lastActivityId); using (var op = SnTrace.Index.StartOperation("IndexPopulator ClearAndPopulateAll")) { // recreate var writer = IndexManager.GetIndexWriter(true); try { var excludedNodeTypes = LuceneManager.GetNotIndexedNodeTypes(); foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath("/Root", excludedNodeTypes)) { var doc = IndexDocumentInfo.GetDocument(docData); if (doc == null) // indexing disabled { continue; } writer.AddDocument(doc); OnNodeIndexed(docData.Path); } RepositoryInstance.Instance.ConsoleWrite(" Commiting ... "); writer.Commit(commitData); RepositoryInstance.Instance.ConsoleWriteLine("ok"); RepositoryInstance.Instance.ConsoleWrite(" Optimizing ... "); writer.Optimize(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } finally { writer.Close(); } RepositoryInstance.Instance.ConsoleWrite(" Deleting indexing activities ... "); LuceneManager.DeleteAllIndexingActivities(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); if (backup) { RepositoryInstance.Instance.ConsoleWrite(" Making backup ... "); BackupTools.BackupIndexImmediatelly(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } op.Successful = true; } }
/*======================================================================================================= IIndexPopulator Members */ // caller: IndexPopulator.Populator, Import.Importer, Tests.Initializer, RunOnce public void ClearAndPopulateAll() { var lastActivityId = IndexingActivityManager.GetLastActivityId(); var commitData = IndexManager.CreateCommitUserData(lastActivityId); using (var traceOperation = Logger.TraceOperation("IndexPopulator ClearAndPopulateAll")) { //-- recreate var writer = IndexManager.GetIndexWriter(true); try { foreach (var docData in StorageContext.Search.LoadIndexDocumentsByPath("/Root")) { var doc = IndexDocumentInfo.GetDocument(docData); writer.AddDocument(doc); OnNodeIndexed(docData.Path); } RepositoryInstance.Instance.ConsoleWrite(" Commiting ... "); writer.Commit(commitData); RepositoryInstance.Instance.ConsoleWriteLine("ok"); RepositoryInstance.Instance.ConsoleWrite(" Optimizing ... "); writer.Optimize(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); } finally { writer.Close(); } RepositoryInstance.Instance.ConsoleWrite(" Deleting indexing activities ... "); IndexingActivityManager.DeleteAllActivities(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); RepositoryInstance.Instance.ConsoleWrite(" Making backup ... "); BackupTools.BackupIndexImmediatelly(); RepositoryInstance.Instance.ConsoleWriteLine("ok"); traceOperation.IsSuccessful = true; } }