Delete indexed paths

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

from groupdocs.search import Index
from groupdocs.search.options import UpdateOptions

documents_folder1 = "./documents"
documents_folder2 = "./documents2"

# Creating an index in the specified folder
index = Index("./index")

# Indexing documents from the specified folders
index.add(documents_folder1)
index.add(documents_folder2)

# Getting indexed paths from the index
indexed_paths1 = index.get_indexed_paths()

# Writing indexed paths to the console
print("Indexed paths:")
for path in indexed_paths1:
    print("\t" + path)

# Deleting indexed path from the index
delete_result = index.delete([documents_folder1], UpdateOptions())

# Getting indexed paths after deletion
indexed_paths2 = index.get_indexed_paths()
print("\nDeleted paths: " + str(delete_result.success_count))

print("\nIndexed paths:")
for path in indexed_paths2:
    print("\t" + path)

The following sample files are used in this example: documents/Einstein.txt, documents/Newton.txt

The following sample file is used in this example: documents2/Curie.txt

Indexed paths:
	documents
	documents2

Deleted paths: 1

Indexed paths:
	documents2

Download full output

More resources

GitHub examples

You may find more code examples in our GitHub repository:

Free online document search App

Along with the full-featured library, we provide a free online document search app. You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our Free Online Document Search App.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.