GroupDocs.Search supports the ability to remove indexed files and folders from an index. Only files or folders that were explicitly added to the index can be deleted. It is not possible to remove a file or folder from the index that is a child of the indexed folder. To delete files and folders inside indexed paths, use the document filter (see Document filtering during indexing). To get a list of indexed paths, use the GetIndexedPaths method of the Index class.
Deleting documents does not rewrite the index. Deleted documents are excluded from search results immediately, but their data remain in the index files until the index is optimized. Therefore, after deleting a large number of documents, call the Optimize method to physically remove them and free up disk space. The DeleteResult object returned by the Delete method contains the total, successful and failed counts, the results for individual items and the error messages.
The following example shows how to remove indexed paths from an index.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder1=@"c:\MyDocuments\";stringdocumentsFolder2=@"c:\MyDocuments2\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified foldersindex.Add(documentsFolder1);index.Add(documentsFolder2);// Getting indexed paths from the indexstring[]indexedPaths1=index.GetIndexedPaths();// Writing indexed paths to the consoleConsole.WriteLine("Indexed paths:");foreach(stringpathinindexedPaths1){Console.WriteLine("\t"+path);}// Deleting indexed path from the indexDeleteResultdeleteResult=index.Delete(newstring[]{documentsFolder1},newUpdateOptions());// Getting indexed paths after deletionstring[]indexedPaths2=index.GetIndexedPaths();Console.WriteLine("\nDeleted paths: "+deleteResult.SuccessCount);Console.WriteLine("\nIndexed paths:");foreach(stringpathinindexedPaths2){Console.WriteLine("\t"+path);}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: