Sometimes a situation arises when an indexed document is renamed, but its contents have not changed. In this case, to save computing resources, you can notify the index about the renaming of the document, and then the document will not be reindexed during the update operation.
To notify an index about renaming a document, the Notify method is used with the corresponding notification object as a parameter.
You should keep in mind that if an index is notified of the renaming of a document, it will not be reindexed the next time you call the Update method, even if its contents have changed. The following example demonstrates how to notify an index of a renamed document.
C#
stringindexFolder=@"c:\MyIndex";stringdocumentFolder=@"c:\MyDocuments";// Creating an indexIndexindex=newIndex(indexFolder);// Indexing documents in a document folderindex.Add(documentFolder);// Renaming a documentstringoldDocumentPath=@"c:\MyDocuments\OldDocumentName.txt";stringnewDocumentPath=@"c:\MyDocuments\NewDocumentName.txt";File.Move(oldDocumentPath,newDocumentPath);// Notifying the index about renamingNotificationnotification=Notification.CreateRenameNotification(oldDocumentPath,newDocumentPath);boolresult=index.Notify(notification);// Updating the index// The renamed document will not be reindexedindex.Update();
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: