// caller: IndexPopulator.Populator public void RebuildIndexDirectly(string path, IndexRebuildLevel level = IndexRebuildLevel.IndexOnly) { if (level == IndexRebuildLevel.DatabaseAndIndex) { using (var op2 = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index documents.")) { using (new SystemAccount()) { var node = Node.LoadNode(path); DataBackingStore.SaveIndexDocument(node, false, false, out _); Parallel.ForEach(NodeQuery.QueryNodesByPath(node.Path, true).Nodes, n => { DataBackingStore.SaveIndexDocument(n, false, false, out _); }); } op2.Successful = true; } } using (var op = SnTrace.Index.StartOperation("IndexPopulator: Rebuild index.")) { IndexManager.IndexingEngine.WriteIndex( new[] { new SnTerm(IndexFieldName.InTree, path) }, null, SearchManager.LoadIndexDocumentsByPath(path, IndexManager.GetNotIndexedNodeTypes()) .Select(d => { var indexDoc = IndexManager.CompleteIndexDocument(d); OnNodeIndexed(d.Path); return(indexDoc); })); op.Successful = true; } }
/*======================================================================================================= IIndexPopulator Members */ // caller: IndexPopulator.Populator, Import.Importer, Tests public void ClearAndPopulateAll(TextWriter consoleWriter = null) { using (var op = SnTrace.Index.StartOperation("IndexPopulator ClearAndPopulateAll")) { // recreate consoleWriter?.Write(" Cleanup index ... "); IndexManager.ClearIndex(); consoleWriter?.WriteLine("ok"); IndexManager.AddDocuments( SearchManager.LoadIndexDocumentsByPath("/Root", IndexManager.GetNotIndexedNodeTypes()) .Select(d => { var indexDoc = IndexManager.CompleteIndexDocument(d); OnNodeIndexed(d.Path); return(indexDoc); })); consoleWriter?.Write(" Commiting ... "); IndexManager.Commit(); // explicit commit consoleWriter?.WriteLine("ok"); consoleWriter?.Write(" Deleting indexing activities ... "); IndexManager.DeleteAllIndexingActivities(); op.Successful = true; } }
/*================================================================================================================================*/ private IEnumerable <IndexDocument> LoadIndexDocumentsByPath(string path) { return(SearchManager.LoadIndexDocumentsByPath(path, IndexManager.GetNotIndexedNodeTypes()) .Select(d => { try { var indexDoc = IndexManager.CompleteIndexDocument(d); OnNodeIndexed(d.Path, d.NodeId, d.VersionId, indexDoc.Version); return indexDoc; } catch (Exception e) { OnIndexingError(d, e); return null; } }) .Where(d => d != null)); }