This page contains a description of updating indexed documents, as well as updating an index version.
Update indexed documents
The update operation is used to reindex documents that have been changed, deleted or added to indexed folders. Changing a filter specified by the document_filter property of the IndexSettings class can also lead to a change in the list of indexed documents.
The update operation also indexes again the documents whose previous indexing was not completed. For example, a document whose indexing was interrupted by cancellation is marked with the indexed_with_error flag and is indexed again by the next update. Note that only documents indexed from files can be indexed again: documents added from streams, structures or extracted data have to be added again. In the same way, the update indexes again the files of documents deleted when a damaged index is repaired (see Checking index integrity).
When updating, the same options can be specified in the instance of the UpdateOptions class, which are set in the IndexingOptions class to specify indexing options. See the Indexing options page.
The following example demonstrates how to update an index using 2 threads.
fromgroupdocs.searchimportIndexfromgroupdocs.search.optionsimportUpdateOptions# Creating an index in the specified folderindex=Index("./index")# Indexing documents from the specified folderindex.add("./documents")# Change, delete, add documents in the document folder# ...options=UpdateOptions()options.threads=2# Setting the number of indexing threadsindex.update(options)# Updating the indexprint("Indexed documents:",len(index.get_indexed_documents()))
When a new version of the GroupDocs.Search library changes the format for storing the index on disk, an index created by a previous version has to be updated to the new format with the IndexUpdater class. Version 26.10 introduces a new index format: an index of a previous version, including versions 26.7 and 26.8, cannot be opened until its version is updated, and the Index constructor raises RuntimeError for it.
An index created by versions 22.7–26.8 is converted to the new format without re-indexing, so the source documents are not required.
An index created by versions 18.5–22.6 is updated by indexing the documents again, so the documents must be available at the paths from which they were indexed.
The source index is never modified. The updated index is written to another folder, which must not be the source folder, a folder that contains it or a folder inside it. The content of the target folder is deleted before the updated index is written.
The method returns a value of the VersionUpdateResult enumeration: UPDATED, ALREADY_UP_TO_DATE (the index already has the current version) or UNSUPPORTED (the folder does not contain an index that can be updated).
The is_latest_version method checks whether a folder contains an index of the current version, and the can_update_version method checks whether a folder contains an index of a previous version that can be updated. After a successful update, the folder containing the old version of the index may be deleted. The full rules, including the exceptions and the settings of an updated index, are described on the Index format and compatibility page.
The following example demonstrates updating a previous version of an index.
fromgroupdocs.searchimportIndex,IndexUpdaterfromgroupdocs.search.commonimportVersionUpdateResultsource_index_folder="./old-index"target_index_folder="./new_index"updater=IndexUpdater()ifupdater.is_latest_version(source_index_folder):# The index has the current version and can be opened without updatingindex=Index(source_index_folder)print("The index has the current version")elifupdater.can_update_version(source_index_folder):# The index of the old version does not changeresult=updater.update_version(source_index_folder,target_index_folder)ifresult==VersionUpdateResult.UPDATED:# Opening the updated indexindex=Index(target_index_folder)print("The index is updated: "+str(len(index.get_indexed_documents()))+" documents")
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.