Update index

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Search MCP server lets your agent work with files on your machine; they are never uploaded. It runs in Docker: replace /path/to/documents with the folder it may use.

claude mcp add groupdocs-search -- docker run --rm -i -v /path/to/documents:/data ghcr.io/groupdocs-search/search-net-mcp:latest
Folders, licensing and more →

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).

Since version 26.11, a changed file that the update indexes again keeps the attributes of its indexed version, also those changed by the ChangeAttributes method (see Document attributes). A handler of the FileIndexing event sees these attributes in the Attributes property of the event arguments and replaces them if it sets the property. The additional fields of a document added from a file are not kept: give them in the FileIndexing event if they must stay (see Indexing additional fields).

Also since version 26.11:

  • The time of the last change of a file is recorded before the text of the file is extracted, so a file that changes while it is indexed is indexed again by the next update.
  • The links to folders inside the indexed folders, such as symbolic links and junctions, are not followed: the next update deletes from the index the files indexed under such a link (see Indexing from different sources).

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#

string indexFolder = @"c:\MyIndex\";
string documentFolder = @"c:\MyDocuments\";
 
// Creating an index in the specified folder
Index index = new Index(indexFolder);
 
// Indexing documents from the specified folder
index.Add(documentFolder);
 
// Change, delete, add documents in the document folder
// ...
 
UpdateOptions options = new UpdateOptions();
options.Threads = 2; // Setting the number of indexing threads
index.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. Since version 26.11, an index that a newer version of the library has created or changed is refused with InvalidOperationException as well, and none of its files is changed.

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. Since version 26.11, the method throws IOException and does not change the target folder if another Index object uses it, in this process or in another one: dispose of such an object first.
  • Since version 26.11, the synonyms and homophones of every word are kept as they are. Before, the words of the groups that shared a word became synonyms of each other.
  • 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#

string sourceIndexFolder = @"c:\MyOldIndex\";
string targetIndexFolder = @"c:\MyNewIndex\";
 
IndexUpdater updater = new IndexUpdater();
 
if (updater.IsLatestVersion(sourceIndexFolder))
{
    // The index has the current version and can be opened without updating
    Index index = new Index(sourceIndexFolder);
}
else if (updater.CanUpdateVersion(sourceIndexFolder))
{
    // The index of the old version does not change
    VersionUpdateResult result = updater.UpdateVersion(sourceIndexFolder, targetIndexFolder);
    if (result == VersionUpdateResult.Updated)
    {
        // Opening the updated index
        Index index = new Index(targetIndexFolder);
    }
}

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.