How to add folder to index with GroupDocs.Search in Java
If you need java full text search that can scale to millions of documents, you’re in the right place. In this tutorial you’ll learn how to add folder to index using GroupDocs.Search, configure high‑compression storage, and run lightning‑fast queries. By the end you’ll have a production‑ready solution you can drop into any Java project.
Quick answers
- What is the primary library? GroupDocs.Search for Java
- How to add a folder to index? Use
index.add(folderPath) - Can I configure text compression? Yes, via
TextStorageSettings(Compression.High) - Which Java version is required? JDK 8 or higher
- Where to get a trial license? From the GroupDocs website or the repository page
What is java full text search and why it matters?
Java full text search converts raw documents into an inverted index, enabling sub‑second retrieval of any term across thousands of files. This capability is essential for legal repositories, research libraries, and enterprise knowledge bases where users expect instant results. It also improves productivity in modern applications.
Why use groupdocs.search for java full text search?
GroupDocs.Search delivers high‑throughput indexing and query execution while offering built‑in high compression. It supports 50+ input and output formats—including PDF, DOCX, EML, and HTML—and can process multi‑hundred‑page documents without loading the entire file into memory, keeping the memory footprint under 200 MB for typical workloads.
Prerequisites
- GroupDocs.Search for Java (version 25.4 or later) – the core library that powers indexing and searching.
- JDK 8+ installed and configured – the minimum runtime required for the SDK.
- Maven for dependency management – simplifies adding the library to your project.
- An IDE such as IntelliJ IDEA or Eclipse – for writing and debugging Java code.
Setting up GroupDocs.Search for java
Maven setup
Add the repository and dependency to your pom.xml file:
<repositories>
<repository>
<id>repository.groupdocs.com</id>
<name>GroupDocs Repository</name>
<url>https://releases.groupdocs.com/search/java/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-search</artifactId>
<version>25.4</version>
</dependency>
</dependencies>
Direct download
Alternatively, download the latest version from GroupDocs.Search for Java releases.
License acquisition
- Free trial – explore all features without commitment.
- Temporary license – extended testing period.
- Purchase – unlock full production capabilities.
Basic initialization and setup
Index is the core class used to create, open, and manage a search index.
import com.groupdocs.search.Index;
public class InitializeSearch {
public static void main(String[] args) {
// Path to store index data
String indexPath = "path/to/index";
// Creating an index at specified location
Index index = new Index(indexPath);
System.out.println("GroupDocs.Search initialized successfully!");
}
}
Index text with custom compression
Step 1: define the index folder
Choose a directory where the index files will reside:
String indexFolder = "YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\StoringTextOfIndexedDocuments";
Step 2: configure index settings
TextStorageSettings configures how text is stored in the index, including compression level. Compression is an enum that specifies the desired compression algorithm.
import com.groupdocs.search.Index;
import com.groupdocs.search.IndexSettings;
import com.groupdocs.search.options.TextStorageSettings;
import com.groupdocs.search.compression.Compression;
IndexSettings settings = new IndexSettings();
settings.setTextStorageSettings(new TextStorageSettings(Compression.High));
Step 3: create the index with custom settings
Instantiate the index using the configuration defined above:
Index index = new Index(indexFolder, settings);
System.out.println("Index created with high compression.");
How to add a folder to index
Index is the main class representing the searchable index.
Load the existing index (or create a new one) and then call the add method on the Index object. The add operation scans the supplied directory, extracts text from each supported file, and stores it in the compressed index, ready for instant search.
String documentsFolder = "YOUR_DOCUMENT_DIRECTORY"; // Replace with actual document path.
Index index = new Index(indexFolder);
How to search indexed documents
SearchResult represents a single match with document path and relevance.
Define a search query string that represents the term or phrase you want to locate, then invoke the search method on the Index instance. The method returns a collection of SearchResult objects, each containing the document path, relevance score, and snippet highlighting the match.
index.add(documentsFolder);
System.out.println("Documents added successfully.");
Practical applications
Real‑world scenarios where java full text search shines:
- Legal document management – instant retrieval of case files.
- Academic research libraries – fast lookup of papers and theses.
- Enterprise knowledge bases – quick access to manuals and FAQs.
- Content management systems – efficient content discovery for large sites.
- Customer service archives – rapid search of past tickets and chats.
Performance considerations
- Compression vs. speed: High compression saves up to 70 % disk space but adds a modest indexing overhead; run benchmark tests for your data volume.
- Memory management: Allocate at least 2 GB of heap for indexes larger than 10 GB to avoid
OutOfMemoryError. - Index updates: Incrementally add new documents with
index.add()and periodically callindex.optimize()to keep the index compact. - Query optimization: Use the advanced query syntax (wildcards, proximity, fuzzy search) to narrow results and reduce response time.
Common pitfalls & pro tips
Pitfall: Forgetting to call
index.optimize()after bulk additions.
Pro tip: Runindex.optimize()nightly to keep the index compact.Pitfall: Using the default (low) compression on massive datasets.
Pro tip: Switch toCompression.Highfor production environments to cut storage costs.Pitfall: Not handling
IOExceptionwhen adding files from a network share.
Pro tip: Wrapindex.add()in a try‑catch block and log any failures for later review.
Frequently asked questions
Q: What is GroupDocs.Search?
A: It is a robust Java library that provides advanced full‑text search capabilities, including indexing, compression, and complex query support.
Q: How do I handle large datasets with GroupDocs.Search?
A: Enable high compression (Compression.High) and periodically commit changes to keep the index lean. Also, allocate sufficient heap memory (e.g., 4 GB for indexes over 20 GB).
Q: Can I integrate GroupDocs.Search with existing enterprise systems?
A: Yes, the library can be embedded in any Java‑based backend, REST services, or micro‑services architecture.
Q: What if my index becomes outdated?
A: Use the index.add() method to append new files and index.delete() to remove obsolete ones, then re‑run index.optimize() if needed.
Q: Where can I get help or support?
A: Visit the community forum at GroupDocs forums for troubleshooting and best‑practice tips.
Additional resources
- Detailed usage guide: GroupDocs Search Documentation
- Full API reference: API Reference Guide
- Stay up‑to‑date with new features: Latest Releases
Last Updated: 2026-11-02
Tested With: GroupDocs.Search 25.4
Author: GroupDocs
String query = "sample";
import com.groupdocs.search.results.SearchResult;
SearchResult result = index.search(query);
System.out.println("Search completed. Results found: " + result.getDocumentCount());