GroupDocs.Search for Java の高度なインデックス作成テクニックで検索パフォーマンスを最適化する
今日の高速に変化するデジタル環境では、検索パフォーマンスの最適化はユーザーに瞬時の結果を提供するために不可欠です。カスタム検索エンジンを構築する場合でも、既存のドキュメント管理システムを強化する場合でも、適切なインデックス作成戦略によりレイテンシを大幅に削減し、リソース消費を抑え、全体的に検索レイテンシの改善が可能になります。このチュートリアルでは、GroupDocs.Search for Java の最も強力な機能—キャンセル、非同期インデックス作成、マルチスレッド、メタデータカスタマイズ—を順に解説し、add documents index をより速く、効率的に行えるようにします。
What You’ll Learn
- 指定した時間後にインデックス作成操作をキャンセルする方法
- 非同期インデックス作成操作を実行し、ステータス変更を処理する方法
- より高速なインデックス作成のためにマルチスレッドを構成する方法
- メタデータインデックス作成オプションをカスタマイズする方法
コードに入る前に、必要なものがすべて揃っていることを確認しましょう。
Prerequisites
- GroupDocs.Search Library – バージョン 25.4 以降。
- Java Development Environment – JDK 8 以上を推奨。
- Java とインデックス作成の概念に関する基本的な知識。
Setting Up GroupDocs.Search for Java
Maven Installation
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 JAR from GroupDocs.Search for Java releases.
License Acquisition – Start with a free trial or request a temporary license to unlock the full feature set.
Basic Initialization and Setup
import com.groupdocs.search.*;
public class IndexSetup {
public static void main(String[] args) {
String indexFolder = "YOUR_OUTPUT_DIRECTORY\\Index";
// Create an instance of the Index class
Index index = new Index(indexFolder);
System.out.println("Index created at: " + indexFolder);
}
}
Quick Answers
- What does cancellation do? Stops indexing after a set time to free resources.
- Can I index documents asynchronously? Yes – set
options.setAsync(true). - How many threads can I use? Any positive integer; typical values are 2‑4 for most servers.
- Is metadata indexing optional? Absolutely – you can enable or fine‑tune it per field.
- Do I need a license for these features? A trial works for testing; a full license is required for production.
What Is “Optimize Search Performance” in This Context?
検索パフォーマンスの最適化とは、CPU、メモリ、時間の消費を適切に抑えつつ、最も関連性の高い結果を瞬時に提供できるようインデックス作成プロセスを構成することです。キャンセル、非同期実行、スレッド化、メタデータ処理を制御することで、エンジンが add documents index し、クエリに応答する速度に直接影響を与えます。
Why Use Advanced Indexing Features?
- Reduced latency – 非同期およびマルチスレッドインデックス作成によりアプリケーションの応答性が向上します。
- Better resource management – キャンセル機能でリソースの過剰消費を防止します。
- Tailored search relevance – メタデータオプションで最重要情報を優先的に検索結果に反映できます。
How to improve search latency with advanced indexing?
検索レイテンシを改善するには、以下の機能を組み合わせて活用してください:長時間実行されるジョブをキャンセルし、バックグラウンドでインデックス作成を実行し、複数の CPU コアに作業を分散させます。この多面的アプローチが最も大きな速度向上をもたらすことが多いです。
Implementation Guide
Cancellation Property
Overview – 指定した期間が経過した後にインデックス作成をキャンセルし、リソースの過剰消費を防止します。
Step 1: Set Up the Environment
import com.groupdocs.search.*;
import com.groupdocs.search.options.*;
String indexFolder = "YOUR_OUTPUT_DIRECTORY\\CancellationProperty";
String documentFolder = "YOUR_DOCUMENT_DIRECTORY";
Step 2: Create Indexing Options with Cancellation
// Create an instance of Index and IndexingOptions
Index index = new Index(indexFolder);
IndexingOptions options = new IndexingOptions();
// Set a cancellation object
options.setCancellation(new Cancellation());
options.getCancellation().cancelAfter(3000);
// Add documents to the index with these options
index.add(documentFolder, options);
Key Points
setCancellation()が機能を有効化します。cancelAfter(int milliseconds)でタイムアウトを設定します(この例では 3 秒)。
Asynchronous Property
Overview – バックグラウンドスレッドでインデックス作成を実行し、ステータス変更を監視します。
Step 1: Set Up the Environment
import com.groupdocs.search.*;
import com.groupdocs.search.events.*;
String indexFolder = "YOUR_OUTPUT_DIRECTORY\\IsAsyncProperty";
String documentFolder = "YOUR_DOCUMENT_DIRECTORY";
Step 2: Subscribe to Status Changed Event
Index index = new Index(indexFolder);
// Subscribe to the status changed event
index.getEvents().StatusChanged.add(new EventHandler<BaseIndexEventArgs>() {
@Override
public void invoke(Object sender, BaseIndexEventArgs args) {
if (args.getStatus() == IndexStatus.Ready || args.getStatus() == IndexStatus.Failed) {
System.out.println("Operation completed with status: " + args.getStatus());
}
}
});
Step 3: Configure Asynchronous Options
IndexingOptions options = new IndexingOptions();
options.setAsync(true);
index.add(documentFolder, options);
Threads Property
Overview – 複数の CPU コアを活用してインデックス作成を高速化します。
Step 1: Set Up Environment
import com.groupdocs.search.*;
import com.groupdocs.search.options.*;
String indexFolder = "YOUR_OUTPUT_DIRECTORY\\ThreadsProperty";
String documentFolder = "YOUR_DOCUMENT_DIRECTORY";
Step 2: Configure Multi‑threading
Index index = new Index(indexFolder);
IndexingOptions options = new IndexingOptions();
// Specify 2 threads for the operation
options.setThreads(2);
index.add(documentFolder, options);
Metadata Indexing Options Property
Overview – どのドキュメントメタデータをインデックス化し、どのように保存するかを細かく調整します。
Step 1: Set Up Environment
import com.groupdocs.search.*;
import com.groupdocs.search.options.*;
String indexFolder = "YOUR_OUTPUT_DIRECTORY\\MetadataIndexingOptionsProperty";
String documentFolder = "YOUR_DOCUMENT_DIRECTORY";
Step 2: Configure Metadata Options
Index index = new Index(indexFolder);
IndexingOptions options = new IndexingOptions();
// Customize metadata indexing options
options.getMetadataIndexingOptions().setDefaultFieldName("default");
options.getMetadataIndexingOptions().setSeparatorInCompoundName("\\");
options.getMetadataIndexingOptions().setMaxBytesToIndexField(10);
options.getMetadataIndexingOptions().setMaxIntsToIndexField(10);
options.getMetadataIndexingOptions().setMaxLongsToIndexField(10);
options.getMetadataIndexingOptions().setMaxDoublesToIndexField(10);
index.add(documentFolder, options);
Practical Applications
- Document Management Systems – 大量バッチをバックグラウンドで処理しながら UI の応答性を保つために非同期インデックス作成を使用します。
- Content Search Engines – ピーク時のサーバーリソース占有を防ぐためにキャンセル機能を適用します。
- Large‑Scale Ingestion Pipelines – スケールで add documents index するためにマルチスレッドを活用し、処理時間を劇的に短縮します。
Performance Considerations
- Thread Management – CPU 使用率を監視してください。スレッドが多すぎるとコンテキストスイッチのオーバーヘッドが発生します。
- Memory Footprint –
setMaxBytesToIndexFieldなどのメタデータ制限を使用してメモリ使用量を予測可能に保ちます。 - Garbage Collection – 大規模コーパスをインデックス化する際は適切な JVM フラグ(
-Xmx,-XX:+UseG1GC)を使用してください。
Common Issues and Solutions
| Symptom | Likely Cause | Fix |
|---|---|---|
| Indexing never finishes | Cancellation set too low | Increase cancelAfter value or remove cancellation for long jobs |
| No status updates in async mode | Event handler not attached correctly | Ensure index.getEvents().StatusChanged.add(...) is called before index.add |
| Out‑of‑memory errors | Too many threads or high metadata limits | Reduce options.setThreads and lower metadata field limits |
| Missing metadata in results | Metadata indexing disabled | Verify options.getMetadataIndexingOptions() is configured and not set to ignore fields |
Frequently Asked Questions
Q: How do I obtain a temporary license for GroupDocs.Search?
A: Visit GroupDocs’ temporary license page.
Q: Can I cancel an indexing operation midway through?
A: Yes – use the cancellation property with cancelAfter() or call Cancellation.cancel() programmatically.
Q: What are some use cases for asynchronous indexing?
A: Real‑time document retrieval, background batch processing, and UI‑responsive applications benefit from async indexing.
Q: Is it safe to increase the thread count on a shared server?
A: Increase gradually and monitor CPU load; on heavily shared environments, keep the thread count modest (2‑4).
Q: How does metadata indexing affect search relevance?
A: Properly indexed metadata (author, creation date, tags) can be weighted higher in queries, improving result accuracy.
Conclusion
GroupDocs.Search for Java のこれら高度な機能を活用することで、さまざまなシナリオ—高速なドキュメント取り込みから細かいメタデータ制御まで—において 検索パフォーマンスの最適化 が実現できます。さまざまな構成を試し、リソース使用状況を監視し、ワークロードに合わせて設定を調整して最高の結果を得てください。
Last Updated: 2026-03-01
Tested With: GroupDocs.Search 25.4 for Java
Author: GroupDocs