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.
// Implementing document loader
privatestaticclassDocumentLoaderimplementsIDocumentLoader{privatefinalStringfilePath;privatefinalStringdocumentKey;publicDocumentLoader(StringfilePath){this.filePath=filePath;documentKey=FilenameUtils.getName(filePath);}publicfinalStringgetDocumentKey(){returndocumentKey;}publicfinalvoidcloseDocument(){}publicfinalDocumentloadDocument(){try{Stringextension="."+FilenameUtils.getExtension(filePath);Pathpath=Paths.get(filePath);byte[]buffer=Files.readAllBytes(path);ByteArrayInputStreamstream=newByteArrayInputStream(buffer);Documentdocument=Document.createFromStream(documentKey,newDate(System.currentTimeMillis()),extension,stream);returndocument;}catch(IOExceptione){thrownewRuntimeException(e);}}}...StringfilePath="c:\\MyDocuments\\SomeDocument.pdf";StringindexFolder="c:\\MyIndex\\";// Creating an index in the specified folder
Indexindex=newIndex(indexFolder);// Indexing the document from stream
DocumentLoaderdocumentLoader=newDocumentLoader(filePath);Documentdocument=Document.createLazy(DocumentSourceKind.Stream,documentLoader.getDocumentKey(),documentLoader);Document[]documents=newDocument[]{document};index.add(documents,newIndexingOptions());// Searching in the index
SearchResultsearchResult=index.search("Einstein");// Deleting indexed document from the index
String[]documentKeys=newString[]{documentLoader.getDocumentKey()};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: