How to Redact Documents with GroupDocs Search in .NET
In modern enterprises, how to redact documents quickly and securely is a daily challenge. Using GroupDocs.Search together with GroupDocs.Redaction for .NET gives you a robust, out‑of‑the‑box solution that not only redacts sensitive content but also lets you perform fuzzy searches and highlight search results in HTML. This tutorial walks you through installing the libraries, creating an index, running a fuzzy query, and producing highlighted output—all with clear, production‑ready code snippets.
Quick Answers
- What is the first step? Install the GroupDocs.Search and GroupDocs.Redaction NuGet packages.
- Can I redact PDFs and Word files? Yes, both formats are supported out of the box.
- Is fuzzy search available? Absolutely – you can tune accuracy from 0 % to 100 %.
- Do I need a license for development? A free trial license works for testing; a paid license is required for production.
- Will the solution work on .NET 6? Yes, the libraries are compatible with .NET Framework 4.5+, .NET Core 3.1+, .NET 5+, and .NET 6+.
What is GroupDocs.Search?
GroupDocs.Search is a .NET library that provides fast indexing and full‑text searching across more than 100 file formats. It can process documents up to 2 GB without loading the entire file into memory, making it ideal for large‑scale repositories. It supports incremental indexing, multilingual analysis, and integrates seamlessly with .NET applications, allowing developers to build powerful search experiences with minimal code.
Why use GroupDocs.Redaction for document redaction?
GroupDocs.Redaction offers over 30 built‑in redaction patterns and supports batch processing, ensuring that personal data, confidential clauses, or regulatory markings are permanently removed. In benchmark tests, redacting a 500‑page PDF takes under 2 seconds on a standard server. The engine works on the document’s content stream, ensuring that redacted areas cannot be recovered, and it maintains original formatting and layout.
Prerequisites
- Required Libraries: GroupDocs.Search, GroupDocs.Redaction
- Supported Platforms: .NET Framework 4.5+, .NET Core 3.1+, .NET 5+, .NET 6+
- IDE: Visual Studio 2022 or later (any edition)
- Basic Skills: Familiarity with C#, file I/O, and OOP concepts
How do you set up GroupDocs.Search and GroupDocs.Redaction in a .NET project?
Install the NuGet packages via the .NET CLI, Package Manager Console, or the UI, then add a license file to your project. This two‑step setup is all you need before writing any indexing or redaction code. After adding the packages, you should place the license file in the application root and reference the namespaces in your code files.
Setting Up GroupDocs.Redaction for .NET
To start using GroupDocs.Search and GroupDocs.Redaction in your .NET applications, follow these installation steps:
.NET CLI
dotnet add package GroupDocs.Redaction
Package Manager Console
Install-Package GroupDocs.Redaction
NuGet Package Manager UI
Search for “GroupDocs.Redaction” and install the latest version.
License Acquisition Steps
- Free Trial: Sign up on GroupDocs to obtain a temporary license.
- Purchase: For full access, purchase a license from the GroupDocs website.
- Temporary License: Obtain it for evaluation purposes via the provided link.
Basic Initialization and Setup
The Index class represents a searchable index stored on disk and provides methods for adding, updating, and querying documents. After installation, initialize your project with necessary configurations:
using GroupDocs.Search;
using GroupDocs.Redaction;
// Initialize an Index instance to manage document indexing and searching.
Index index = new Index("path/to/index/folder");
Implementation Guide
Creating and Indexing Documents
Overview
This feature demonstrates how to efficiently organize documents by creating an index for a folder containing multiple files.
Step 1: Define Paths
string indexFolder = "YOUR_DOCUMENT_DIRECTORY/ObtainSearchResultInformation";
string documentFolder = "YOUR_DOCUMENT_DIRECTORY/DocumentsPath";
// Create an instance of the Index class.
Index index = new Index(indexFolder);
// Add documents from the specified folder to the index.
index.Add(documentFolder);
Fuzzy Search Setup and Execution
Overview
Fuzzy search allows you to find documents even with minor discrepancies in the search terms. This feature showcases setting up a fuzzy search with adjustable accuracy.
Step 1: Enable Fuzzy Search
using GroupDocs.Search.Options;
SearchOptions options = new SearchOptions();
options.FuzzySearch.Enabled = true;
options.FuzzySearch.FuzzyAlgorithm = new TableDiscreteFunction(3); // Allow up to 3 differences
// Execute the search with fuzzy logic.
SearchResult result = index.Search("favourable OR \"ipsum dolor\"", options);
Console.WriteLine("Documents: " + result.DocumentCount);
Console.WriteLine("Total occurrences: " + result.OccurrenceCount);
Highlight Search Results in HTML Format
Overview
Highlighting search results visually marks relevant sections within a file, facilitating quick analysis.
Step 1: Set Up High Compression
using GroupDocs.Search.Highlighters;
using GroupDocs.Search.Options;
IndexSettings settings = new IndexSettings();
settings.TextStorageSettings = new TextStorageSettings(Compression.High);
// Create an instance of the Index.
Index index = new Index(indexFolder, settings);
index.Add(documentFolder);
Step 2: Highlight and Output
SearchResult result = index.Search("solicitude");
if (result.DocumentCount > 0)
{
FoundDocument document = result.GetFoundDocument(0);
string path = "YOUR_OUTPUT_DIRECTORY/Highlighted.html";
OutputAdapter outputAdapter = new FileOutputAdapter(OutputFormat.Html, path);
Highlighter highlighter = new DocumentHighlighter(outputAdapter);
// Generate highlighted HTML content.
index.Highlight(document, highlighter);
}
Troubleshooting Tips
- Ensure paths are correctly specified to avoid file‑not‑found errors.
- Verify that all necessary permissions for read/write operations on directories are set.
Practical Applications
- Legal Document Review – Quickly locate case‑related terms in massive legal corpora.
- Academic Research – Search across thousands of papers for specific methodologies.
- Business Intelligence – Pull key metrics from quarterly reports without manual digging.
- Customer Support – Scan support tickets for recurring issues and redact personal data before analysis.
- Content Management Systems (CMS) – Enhance content retrieval with fuzzy search and automatic redaction of sensitive snippets.
Performance Considerations
- Optimize index storage settings to balance speed and disk usage.
- Regularly update indexes to keep data current, reducing unnecessary processing.
- Dispose of unused objects promptly to prevent memory leaks, especially when handling large batches.
How to redact sensitive information from a PDF using GroupDocs Redaction?
Redactor is the main class used to apply redaction patterns to supported document formats. Load the target PDF with Redactor redactor = new Redactor("file.pdf"), define a redaction pattern (e.g., redactor.AddRedaction(new RedactionPhrase("confidential"))), and call redactor.Apply() – the library overwrites the original file with redacted content while preserving layout. This one‑step workflow guarantees that no trace of the protected phrase remains.
How to highlight search results in HTML after a fuzzy query?
SearchResultHighlighter provides utilities to generate highlighted HTML snippets from search matches. Execute the fuzzy query, retrieve the matching fragments, and pass them to SearchResultHighlighter.HighlightHtml(matches, "<mark>", "</mark>"). The method wraps each occurrence with the supplied tags, producing an HTML snippet where every relevant term is visually emphasized. The highlighted HTML can be embedded directly into web pages or saved as a report, making it easy for end‑users to see the context of each match.
Frequently Asked Questions
Q: What is fuzzy search?
A: Fuzzy search finds approximate matches, tolerating misspellings or slight variations in the query term.
Q: Can I use these libraries in a commercial project?
A: Yes, a valid GroupDocs license grants commercial usage rights.
Q: How do I handle large document sets efficiently?
A: Use incremental indexing, tune IndexingOptions for batch size, and schedule regular index rebuilds to keep performance optimal.
Q: What file formats are supported by GroupDocs.Search?
A: Over 100 formats are supported, including PDF, DOCX, XLSX, PPTX, HTML, TXT, and image types such as JPEG and PNG.
Q: Is there multilingual support for search and redaction?
A: Yes, the libraries include language analyzers for more than 30 languages, enabling accurate searching and redaction across global content.
Resources
Last Updated: 2026-07-16
Tested With: GroupDocs.Search 2.0.0 and GroupDocs.Redaction 2.0.0 for .NET
Author: GroupDocs