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 argument of the setDocumentFilter method of the IndexSettings class can also lead to a change in the list of indexed documents.
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.
constindexFolder='c:/MyIndex/';constdocumentFolder='c:/MyDocuments/';constquery='son';// Creating an index in the specified folder
constindex=newgroupdocs.search.Index(indexFolder);// Indexing documents from the specified folder
index.add(documentFolder);// Change, delete, add documents in the document folder
// ...
constoptions=newgroupdocs.search.UpdateOptions();options.setThreads(2);// Setting the number of indexing threads
index.update(options);// Updating the index
Update index version
Sometimes when a new version of the GroupDocs.Search library is released, the format for storing the index on disk changes. In this case, you also need to update the index. However, updating the index version is different. To do this, use the IndexUpdater class. Without updating the index version, loading the index of the previous version will fail.
When the index version is updated, the documents are reindexed and saved in a folder different from the original in the new format. However, the index of old version does not change. The folder containing the old version of the index may be deleted after the update. The following example demonstrates updating a previous version of an index.
constsourceIndexFolder='c:/MyOldIndex/';consttargetIndexFolder='c:/MyNewIndex/';// Creating updater
constupdater=newgroupdocs.search.IndexUpdater();if(updater.canUpdateVersion(sourceIndexFolder)){// The index of old version does not change
constresult=updater.updateVersion(sourceIndexFolder,targetIndexFolder);}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: