How to Create Index in .NET with GroupDocs Search API

In this tutorial you’ll discover how to create index for your .NET applications using GroupDocs.Search and then protect sensitive content with GroupDocs.Redaction. By the end of the guide you’ll be able to build, update, and prune a searchable index, and you’ll understand why combining search and redaction is a best‑practice for secure document management.

Quick Answers

  • What does “how to create index” mean? It means building a searchable data structure that maps document content to fast lookup keys.
  • Which libraries are required? GroupDocs.Search and GroupDocs.Redaction for .NET (NuGet packages).
  • Can I index PDFs, Word, and images? Yes—over 150 formats are supported out of the box.
  • How do I delete a document from the index? Call the Delete method with the document’s path or ID.
  • Is redaction performed before or after indexing? Redaction should happen first so that protected data never enters the index.

What is “how to create index”?

The phrase how to create index refers to the process of generating a searchable data structure that stores term‑to‑document mappings for rapid retrieval. In GroupDocs, this structure lives on disk and can be updated incrementally without rebuilding the whole collection.

Why use GroupDocs.Search and GroupDocs.Redaction together?

GroupDocs.Search supports indexing of 150+ file formats and can handle indexes larger than 10 GB while keeping memory usage under 200 MB because it streams files instead of loading them entirely. Adding GroupDocs.Redaction ensures that any confidential text, images, or metadata are removed before the content ever reaches the index, guaranteeing compliance with GDPR, HIPAA, and other regulations.

Prerequisites

  • Libraries & Versions – Install the latest GroupDocs.Search and GroupDocs.Redaction NuGet packages that are compatible with .NET 6 or later.
  • IDE – Visual Studio 2022 (or any IDE that supports .NET 6).
  • Knowledge – Basic C# skills, familiarity with file I/O, and an understanding of indexing concepts.

Setting Up GroupDocs.Redaction for .NET

Installation

Using .NET CLI:

dotnet add package GroupDocs.Redaction

Using Package Manager Console in Visual Studio:

Install-Package GroupDocs.Redaction

You can also locate “GroupDocs.Redaction” in the NuGet Package Manager UI and install the newest stable version.

License Acquisition

You can obtain a free trial or request a temporary license to explore all features without limitations. Visit GroupDocs’ Purchase Page for more details on obtaining a license.

Basic Initialization

Redactor is the primary class that performs redaction operations on a document.
The following snippet shows the minimal code required to start using GroupDocs.Redaction:

// Initialize the Redactor with a file path or stream
using (Redactor redactor = new Redactor("input.docx"))
{
    // Your redaction code here
}

This simple setup is all you need to begin using GroupDocs.Redaction.

Implementation Guide

How to create index?

Index represents the searchable container that holds term dictionaries and document metadata.
Load or create an Index object, point it at a folder where the index files will be stored, and call Create. The operation writes the necessary metadata files and prepares the engine for document ingestion.

// Direct answer (40‑70 words):
Create a new `Index` instance by specifying the folder path where the index will reside, then invoke `Create()` to initialise the storage structures. The method writes index headers, term dictionaries, and a lock file, making the folder ready for document addition. This step is required only once per index location.

Step 1: Create the Index

using GroupDocs.Search;

string indexFolder = @"YOUR_DOCUMENT_DIRECTORY/AdvancedUsage/Indexing/DeleteIndexedPaths";
Index index = new Index(indexFolder);
// This line initializes an index at the provided folder path.

How to add documents to the index?

Add inserts a single document into the index, while AddFolder processes all files in a directory.
You add files by calling Add or AddFolder. The engine reads each supported file, extracts text, and updates the term dictionary.

// Direct answer (40‑70 words):
Use `index.AddFolder("C:\\Docs")` or `index.Add("C:\\Docs\\file.pdf")` to feed documents into the index. The API streams each file, extracts searchable text, and stores term‑frequency data without loading the entire file into memory, which lets you index thousands of large PDFs efficiently.

Step 2: Add Document Folders

string documentsFolder1 = @"YOUR_DOCUMENT_DIRECTORY";
string documentsFolder2 = @"YOUR_DOCUMENT_DIRECTORY2";

index.Add(documentsFolder1);  // Adding the first folder of documents to the index
index.Add(documentsFolder2);  // Adding the second folder of documents to the index

How to retrieve indexed paths?

GetIndexedPaths returns a collection of all document paths stored in the index.
Retrieving the list of indexed file paths lets you verify which documents are currently searchable.

// Direct answer (40‑70 words):
Call `index.GetIndexedDocuments()` to obtain a collection of `IndexedDocumentInfo` objects, each containing the original file path, document ID, and indexing timestamp. Loop through the collection and output the `FilePath` property to confirm that every expected file has been successfully added.

Step 3: Display Indexed Paths

string[] indexedPaths1 = index.GetIndexedPaths();
foreach (string path in indexedPaths1)
{
    Console.WriteLine(path); // Outputs the document paths
}

How to delete document from the index?

Delete removes a document from the index by its path or identifier.
When a file is removed or becomes obsolete, you should delete its entry to keep search results accurate.

// Direct answer (40‑70 words):
Invoke `index.Delete("C:\\Docs\\obsolete.pdf")` or `index.Delete(documentId)` to purge a specific document from the index. The method removes all term entries linked to that file, updates the term dictionary, and frees the space on disk, ensuring that future queries no longer return the deleted content.

Step 4: Delete Specific Paths

using GroupDocs.Search.Options;

string[] pathsToDelete = { @"YOUR_DOCUMENT_DIRECTORY" };
DeleteResult deleteResult = index.Delete(pathsToDelete, new UpdateOptions());
// This deletes specified document paths from the index.

How to verify remaining indexed paths after deletion?

After removal, you can re‑run the retrieval method to ensure the index reflects the current state.

// Direct answer (40‑70 words):
Run `index.GetIndexedDocuments()` again and compare the resulting list with the pre‑deletion list. The missing file path confirms successful deletion, while the remaining entries confirm the index’s integrity. This verification step is especially important in automated pipelines.

Step 5: Verify Remaining Paths

string[] indexedPaths2 = index.GetIndexedPaths();
foreach (string path in indexedPaths2)
{
    Console.WriteLine(path); // Displays remaining paths after deletion
}

Practical Applications

  1. Document Management Systems – Quickly locate contracts, invoices, or manuals across millions of files.
  2. Legal Document Review – Redact privileged information before indexing to avoid accidental exposure.
  3. Archival Solutions – Preserve searchable metadata for historic records without loading entire archives into memory.
  4. Content Management Platforms – Power site‑wide search for blogs, knowledge bases, and multimedia libraries.
  5. Data Compliance Audits – Ensure only sanitized content is searchable, meeting regulatory requirements.

Performance Considerations

  • Optimize Indexing – Schedule incremental indexing nightly; use AddFolder with a batch size of 100 files to reduce I/O spikes.
  • Resource Management – Monitor CPU and RAM; GroupDocs.Search processes files in a streaming fashion, keeping peak memory under 200 MB even for 10 GB indexes.
  • Best Practices – Store the index on SSDs for sub‑second query response, and enable compression (index.Compression = true) to halve disk usage.

Frequently Asked Questions

Q: Can I index non‑text files with GroupDocs?
A: Yes, GroupDocs.Search can index over 150 formats—including PDFs, DOCX, PPTX, XLSX, and image types—by extracting embedded text via OCR where necessary.

Q: How do I handle large volumes of documents?
A: Use AddFolder with a configurable batch size, run indexing in a background service, and periodically call Optimize() to merge small index segments.

Q: What are the benefits of using redaction with indexing?
A: Redaction removes personally identifiable information before it ever reaches the index, guaranteeing that search results never expose protected data.

Q: Is it possible to customize search algorithms?
A: GroupDocs.Search provides synonym dictionaries, custom tokenizers, and regular‑expression filters, allowing you to fine‑tune relevance scoring.

Q: How do I troubleshoot common indexing issues?
A: Verify folder permissions, ensure the .NET runtime matches the library’s target, and check the log file generated in the index folder for detailed error messages.

Resources

Explore these resources to deepen your understanding and enhance your implementation of GroupDocs.Search and Redaction in .NET. Happy coding!


Last Updated: 2026-07-26
Tested With: GroupDocs.Search 23.10, GroupDocs.Redaction 23.10 for .NET
Author: GroupDocs