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 a notification object created by the Notification.create_rename_notification method as a parameter. The notify method returns True if the notification was successfully performed.
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.
importosfromgroupdocs.searchimportIndexfromgroupdocs.search.commonimportNotification# Creating an indexindex=Index("./index")# Indexing documents in a document folderindex.add("./documents")# Renaming a documentold_document_path="./documents/OldDocumentName.txt"new_document_path="./documents/NewDocumentName.txt"os.rename(old_document_path,new_document_path)# Notifying the index about renamingnotification=Notification.create_rename_notification(old_document_path,new_document_path)result=index.notify(notification)print("Notification applied:",result)# Updating the index# The renamed document will not be reindexedindex.update()fordocumentinindex.get_indexed_documents():print("Indexed:",os.path.basename(document.file_path))# Restoring the original file name, so that the example can run againos.rename(new_document_path,old_document_path)
Along with the full-featured library, we provide a free online document search app. You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our Free Online Document Search App.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.