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 DocumentFilter 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 IndexedWithError 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.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentFolder);// Change, delete, add documents in the document folder// ...UpdateOptionsoptions=newUpdateOptions();options.Threads=2;// Setting the number of indexing threadsindex.Update(options);// Updating the index
Update index version
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 constructors throw InvalidOperationException for it.
The UpdateVersion method updates an index as follows:
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, AlreadyUpToDate (the index already has the current version) or Unsupported (the folder does not contain an index that can be updated).
The IsLatestVersion method checks whether a folder contains an index of the current version, and the CanUpdateVersion 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.
C#
stringsourceIndexFolder=@"c:\MyOldIndex\";stringtargetIndexFolder=@"c:\MyNewIndex\";IndexUpdaterupdater=newIndexUpdater();if(updater.IsLatestVersion(sourceIndexFolder)){// The index has the current version and can be opened without updatingIndexindex=newIndex(sourceIndexFolder);}elseif(updater.CanUpdateVersion(sourceIndexFolder)){// The index of the old version does not changeVersionUpdateResultresult=updater.UpdateVersion(sourceIndexFolder,targetIndexFolder);if(result==VersionUpdateResult.Updated){// Opening the updated indexIndexindex=newIndex(targetIndexFolder);}}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: