// UpdateDocumentActivity internal static bool UpdateDocument(IndexDocument document, VersioningInfo versioning) { var delTerms = versioning.Delete.Select(i => new SnTerm(IndexFieldName.VersionId, i)).ToArray(); var updates = GetUpdates(versioning).ToList(); if (document != null) { SetDocumentFlags(document, versioning); updates.Add(new DocumentUpdate { UpdateTerm = new SnTerm(IndexFieldName.VersionId, document.VersionId), Document = document }); } IndexingEngine.WriteIndex(delTerms, updates, null); return(true); }
private static void SetDocumentFlags(Document doc, int versionId, VersioningInfo versioning) { var version = GetVersionFromDocument(doc); var isMajor = version.IsMajor; var isPublic = version.Status == VersionStatus.Approved; var isLastPublic = versionId == versioning.LastPublicVersionId; var isLastDraft = versionId == versioning.LastDraftVersionId; // set flags doc.RemoveField(LucObject.FieldName.IsMajor); doc.RemoveField(LucObject.FieldName.IsPublic); doc.RemoveField(LucObject.FieldName.IsLastPublic); doc.RemoveField(LucObject.FieldName.IsLastDraft); SetDocumentFlag(doc, LucObject.FieldName.IsMajor, isMajor); SetDocumentFlag(doc, LucObject.FieldName.IsPublic, isPublic); SetDocumentFlag(doc, LucObject.FieldName.IsLastPublic, isLastPublic); SetDocumentFlag(doc, LucObject.FieldName.IsLastDraft, isLastDraft); }
private void RebuildIndex_NoRecursive(Node node, bool databaseAndIndex) { TreeLock.AssertFree(node.Path); var head = NodeHead.Get(node.Id); if (databaseAndIndex) { foreach (var version in head.Versions.Select(v => Node.LoadNodeByVersionId(v.VersionId))) { DataBackingStore.SaveIndexDocument(version, false, false, out _); } } var versioningInfo = new VersioningInfo { LastDraftVersionId = head.LastMinorVersionId, LastPublicVersionId = head.LastMajorVersionId, Delete = new int[0], Reindex = new int[0] }; CreateActivityAndExecute(IndexingActivityType.Rebuild, node.Path, node.Id, 0, 0, versioningInfo, null); }
// caller: CommitPopulateNode private static void AddNewVersion(Node newVersion, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { CreateActivityAndExecute(IndexingActivityType.AddDocument, newVersion.Path, newVersion.Id, newVersion.VersionId, newVersion.VersionTimestamp, null, versioningInfo, indexDocumentData); }
/*================================================================================================================================*/ // caller: CommitPopulateNode private static void CreateBrandNewNode(Node node, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { CreateActivityAndExecute(IndexingActivityType.AddDocument, node.Path, node.Id, node.VersionId, node.VersionTimestamp, true, versioningInfo, indexDocumentData); }
// UpdateDocumentActivity internal static async STT.Task <bool> UpdateDocumentAsync(IndexDocument document, VersioningInfo versioning, CancellationToken cancellationToken) { var delTerms = versioning.Delete.Select(i => new SnTerm(IndexFieldName.VersionId, i)).ToArray(); var updates = GetUpdates(versioning).ToList(); if (document != null) { SetDocumentFlags(document, versioning); updates.Add(new DocumentUpdate { UpdateTerm = new SnTerm(IndexFieldName.VersionId, document.VersionId), Document = document }); } await IndexingEngine.WriteIndexAsync(delTerms, updates, null, cancellationToken).ConfigureAwait(false); return(true); }
private static STT.Task CreateActivityAndExecuteAsync(IndexingActivityType type, string path, int nodeId, int versionId, long versionTimestamp, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData, CancellationToken cancellationToken) { return(ExecuteActivityAsync(CreateActivity(type, path, nodeId, versionId, versionTimestamp, versioningInfo, indexDocumentData), cancellationToken)); }
/*================================================================================================================================*/ private static IndexingActivityBase CreateActivity(IndexingActivityType type, string path, int nodeId, int versionId, long versionTimestamp, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { var activity = (IndexingActivityBase)IndexingActivityFactory.Instance.CreateActivity(type); activity.Path = path.ToLowerInvariant(); activity.NodeId = nodeId; activity.VersionId = versionId; activity.VersionTimestamp = versionTimestamp; if (indexDocumentData != null) { if (activity is DocumentIndexingActivity docAct) { docAct.IndexDocumentData = indexDocumentData; } } if (activity is DocumentIndexingActivity documentActivity) { documentActivity.Versioning = versioningInfo; } return(activity); }
private static void CreateActivityAndExecute(IndexingActivityType type, string path, int nodeId, int versionId, long versionTimestamp, bool?singleVersion, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { ExecuteActivity(CreateActivity(type, path, nodeId, versionId, versionTimestamp, singleVersion, versioningInfo, indexDocumentData)); }
internal static bool DeleteDocuments(Term[] deleteTerms, bool moveOrRename, int activityId, bool executingUnprocessedActivities, VersioningInfo versioning) { if (!IsActivityExecutable(executingUnprocessedActivities)) { SnTrace.Index.Write("LM: DeleteDocuments skipped #1. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, MoveOrRename:{2}", activityId, executingUnprocessedActivities, moveOrRename); return(false); } if (SnTrace.Index.Enabled) { SnTrace.Index.Write("LM: DeleteDocuments. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, terms:{2}", activityId, executingUnprocessedActivities, string.Join(", ", deleteTerms.Select(t => { var name = t.Field(); var value = t.Text(); if (name == "VersionId") { value = GetIntFromPrefixCode(value).ToString(); } return(name + ":" + value); })) ); } using (var wrFrame = IndexWriterFrame.Get(false)) // // DeleteDocuments { wrFrame.IndexWriter.DeleteDocuments(deleteTerms); } // don't need to check if indexing interfered here. If it did, change is detected in overlapped adddocument/updatedocument, and refresh (re-delete) is called there. // deletedocuments will never detect change in index, since it sets timestamp in indexhistory to maxvalue. return(true); }
internal static bool DeleteDocument(int nodeId, int versionId, bool moveOrRename, int activityId, bool executingUnprocessedActivities, VersioningInfo versioning) { if (!IsActivityExecutable(executingUnprocessedActivities)) { SnTrace.Index.Write("LM: DeleteDocument skipped #1. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, MoveOrRename:{2}", activityId, executingUnprocessedActivities, moveOrRename); return(false); } SnTrace.Index.Write("LM: DeleteDocument. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, NodeId:{2}, VersionId:{3}", activityId, executingUnprocessedActivities, nodeId, versionId); var deleteTerm = GetVersionIdTerm(versionId); var updates = GetUpdates(versioning); using (var wrFrame = IndexWriterFrame.Get(false)) // // DeleteDocuments { wrFrame.IndexWriter.DeleteDocuments(versioning.Delete.Select(i => GetVersionIdTerm(i)).ToArray()); foreach (var update in updates) { wrFrame.IndexWriter.UpdateDocument(update.UpdateTerm, update.Document); } wrFrame.IndexWriter.DeleteDocuments(deleteTerm); } return(true); }
internal static bool UpdateDocument(int activityId, bool executingUnprocessedActivities, VersioningInfo versioning) { if (!IsActivityExecutable(executingUnprocessedActivities)) { SnTrace.Index.Write("LM: UpdateDocument skipped #1. ActivityId:{0}, ExecutingUnprocessedActivities:{1}", activityId, executingUnprocessedActivities); return(false); } SnTrace.Index.Write("LM: AddDocument without document. ActivityId:{0}, ExecutingUnprocessedActivities:{1}", activityId, executingUnprocessedActivities); var updates = GetUpdates(versioning); using (var wrFrame = IndexWriterFrame.Get(false)) // // UpdateDocument { wrFrame.IndexWriter.DeleteDocuments(versioning.Delete.Select(i => GetVersionIdTerm(i)).ToArray()); foreach (var update in updates) { wrFrame.IndexWriter.UpdateDocument(update.UpdateTerm, update.Document); } } return(true); }
internal static bool UpdateDocument(Document document, int activityId, bool executingUnprocessedActivities, VersioningInfo versioning) { if (!IsActivityExecutable(executingUnprocessedActivities)) { SnTrace.Index.Write("LM: UpdateDocument skipped #1. ActivityId:{0}, ExecutingUnprocessedActivities:{1}", activityId, executingUnprocessedActivities); return(false); } var nodeId = GetNodeIdFromDocument(document); var versionId = GetVersionIdFromDocument(document); SnTrace.Index.Write("LM: UpdateDocument. ActivityId:{0}, ExecutingUnprocessedActivities:{1}, NodeId:{2}, VersionId:{3}", activityId, executingUnprocessedActivities, nodeId, versionId); var updates = GetUpdates(versioning); SetDocumentFlags(document, versionId, versioning); using (var wrFrame = IndexWriterFrame.Get(false)) // // UpdateDocument { wrFrame.IndexWriter.DeleteDocuments(versioning.Delete.Select(i => GetVersionIdTerm(i)).ToArray()); foreach (var update in updates) { wrFrame.IndexWriter.UpdateDocument(update.UpdateTerm, update.Document); } wrFrame.IndexWriter.UpdateDocument(GetVersionIdTerm(versionId), document); } return(true); }
// caller: CommitPopulateNode private static void UpdateVersion(DocumentPopulatorData state, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { CreateActivityAndExecute(IndexingActivityType.UpdateDocument, state.OriginalPath, state.Node.Id, state.Node.VersionId, state.Node.VersionTimestamp, null, versioningInfo, indexDocumentData); }
// caller: CommitPopulateNode private static STT.Task AddNewVersionAsync(Node newVersion, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData, CancellationToken cancellationToken) { return(CreateActivityAndExecuteAsync(IndexingActivityType.AddDocument, newVersion.Path, newVersion.Id, newVersion.VersionId, newVersion.VersionTimestamp, versioningInfo, indexDocumentData, cancellationToken)); }
/*================================================================================================================================*/ private static LuceneIndexingActivity CreateActivity(IndexingActivityType type, string path, int nodeId, int versionId, long versionTimestamp, bool?singleVersion, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData) { var activity = (LuceneIndexingActivity)IndexingActivityFactory.Instance.CreateActivity(type); activity.Path = path.ToLowerInvariant(); activity.NodeId = nodeId; activity.VersionId = versionId; activity.VersionTimestamp = versionTimestamp; activity.SingleVersion = singleVersion; if (indexDocumentData != null) { var lucDocAct = activity as LuceneDocumentActivity; if (lucDocAct != null) { lucDocAct.IndexDocumentData = indexDocumentData; } } var documentActivity = activity as LuceneDocumentActivity; if (documentActivity != null) { documentActivity.Versioning = versioningInfo; } return(activity); }
// caller: CommitPopulateNode private static STT.Task UpdateVersionAsync(DocumentPopulatorData state, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData, CancellationToken cancellationToken) { return(CreateActivityAndExecuteAsync(IndexingActivityType.UpdateDocument, state.OriginalPath, state.Node.Id, state.Node.VersionId, state.Node.VersionTimestamp, versioningInfo, indexDocumentData, cancellationToken)); }
// RemoveTreeActivity, RebuildActivity internal async STT.Task <bool> DeleteDocumentsAsync(IEnumerable <SnTerm> deleteTerms, VersioningInfo versioning, CancellationToken cancellationToken) { await IndexingEngine.WriteIndexAsync(deleteTerms, null, null, cancellationToken).ConfigureAwait(false); // Not necessary to check if indexing interfered here. If it did, change is detected in overlapped AddDocument/UpdateDocument // operations and refresh (re-delete) is called there. // Delete documents will never detect changes in index, since it sets timestamp in index history to maxvalue. return(true); }
// caller: CommitPopulateNode private STT.Task CreateBrandNewNodeAsync(Node node, VersioningInfo versioningInfo, IndexDocumentData indexDocumentData, CancellationToken cancellationToken) { return(CreateActivityAndExecuteAsync(IndexingActivityType.AddDocument, node.Path, node.Id, node.VersionId, node.VersionTimestamp, versioningInfo, indexDocumentData, cancellationToken)); }