GroupDocs.Search has the ability to remove individual documents from the index that are indexed from a stream or structure. To remove documents indexed by a file system path, see Deleting indexed paths.
The following example shows how to remove documents from an index by document key.
C#
// Implementing document loaderpublicclassDocumentLoader:IDocumentLoader{privatereadonlystringfilePath;privatereadonlystringdocumentKey;publicDocumentLoader(stringfilePath){this.filePath=filePath;documentKey=Path.GetFileName(filePath);}publicstringDocumentKey{get{returndocumentKey;}}publicvoidCloseDocument(){}publicDocumentLoadDocument(){stringextension=Path.GetExtension(filePath);byte[]buffer=File.ReadAllBytes(filePath);Streamstream=newMemoryStream(buffer);Documentdocument=Document.CreateFromStream(documentKey,DateTime.Now,extension,stream);returndocument;}}...stringfilePath=@"c:\MyDocuments\SomeDocument.pdf";stringindexFolder=@"c:\MyIndex\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing the document from streamDocumentLoaderdocumentLoader=newDocumentLoader(filePath);Documentdocument=Document.CreateLazy(DocumentSourceKind.Stream,documentLoader.DocumentKey,documentLoader);Document[]documents=newDocument[]{document};index.Add(documents,newIndexingOptions());// Searching in the indexSearchResultsearchResult=index.Search("Einstein");// Deleting indexed document from the indexstring[]documentKeys=newstring[]{documentLoader.DocumentKey};DeleteResultdeleteResult=index.Delete(newUpdateOptions(),documentKeys);
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: