インデックスにドキュメントを追加して大文字小文字を区別しない検索を行う(Java)
When you need case insensitive search java that reliably finds information regardless of how users type it, the key is to add documents to an index while normalizing the text. In this tutorial we walk through configuring GroupDocs.Search for Java so that every document you index is automatically lower‑cased (or otherwise transformed) during indexing, guaranteeing case‑insensitive results without extra query‑time logic.
クイック回答
- “add documents to index” の意味は何ですか? It means loading source files into a searchable data structure so they can be queried later.
- Why use character replacement? It normalizes every character—typically to lower‑case—so searches ignore case differences automatically.
- Do I need a license? A free trial works for development; a full license is required for production deployments.
- Which Java version is required? Java 8 or newer; the library targets Java 11+ for optimal performance.
- Can I switch to case‑sensitive search when needed? Yes—search options let you toggle case‑sensitivity per query.
GroupDocs.Search における “add documents to index” とは何ですか?
Load your source files (PDF, DOCX, TXT, etc.) into a searchable index so the engine can retrieve them quickly. Adding documents to an index parses each file, extracts plain text, and stores it in an optimized data structure that enables fast look‑ups.
インデックス作成時に文字置換を有効にする理由
Character replacement converts each character to a predefined equivalent—most commonly lower‑case—while the index is built. This ensures that variations in capitalization, diacritics, or locale‑specific symbols do not affect search results. By normalizing text at indexing time, the engine can match queries against a consistent token set, providing fast, reliable case‑insensitive behavior without additional processing during each search.
前提条件
- GroupDocs.Search for Java version 25.4 or newer (the library supports 30+ file formats and can index multi‑hundred‑page documents without loading the whole file into memory).
- Java Development Kit (JDK) 8 or later installed.
- Basic familiarity with Maven (or ability to add JARs manually).
GroupDocs.Search for Java の設定
Maven 設定
Add the GroupDocs repository and dependency to your pom.xml:
<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>
直接ダウンロード
If you prefer not to use Maven, grab the latest JAR from the official site: GroupDocs.Search for Java releases.
ライセンス取得
- Free Trial – download a trial license to start experimenting.
- Temporary License – request an extended testing license from the GroupDocs portal.
- Full License – purchase a production license when you’re ready to go live.
基本初期化(インデックス作成)
The following snippet creates an index folder and enables character replacements:
import com.groupdocs.search.Index;
import com.groupdocs.search.IndexSettings;
String indexFolder = "YOUR_OUTPUT_DIRECTORY/AdvancedUsage/Indexing/CharacterReplacementDuringIndexing";
IndexSettings settings = new IndexSettings();
settings.setUseCharacterReplacements(true);
Index index = new Index(indexFolder, settings);
実装ガイド
インデックス設定で文字置換を有効にする
Activating this feature tells the engine to replace characters while indexing, which is the core step for case‑insensitive behavior.
手順 1: IndexSettings の設定
IndexSettings is the configuration object that controls how the index stores and processes text. By setting useCharacterReplacements to true, you turn on automatic lower‑casing (or any custom mapping you provide).
import com.groupdocs.search.Index;
import com.groupdocs.search.IndexSettings;
String indexFolder = "YOUR_OUTPUT_DIRECTORY/AdvancedUsage/Indexing/CharacterReplacementDuringIndexing";
// Create an instance of IndexSettings and enable character replacement.
IndexSettings settings = new IndexSettings();
settings.setUseCharacterReplacements(true);
// Initialize the index with these settings.
Index index = new Index(indexFolder, settings);
文字置換の設定
Map each character to its lower‑case counterpart (or any custom mapping you need).
手順 2: 置換ペアの定義と追加
The replacement dictionary holds pairs such as 'A' → 'a', 'É' → 'e', etc. Adding these pairs before indexing ensures every token is normalized.
import com.groupdocs.search.dictionaries.CharacterReplacementPair;
// Access existing replacements and clear them.
index.getDictionaries().getCharacterReplacements().clear();
// Create an array for new replacements.
CharacterReplacementPair[] characterReplacements = new CharacterReplacementPair[Character.MAX_VALUE + 1];
for (int i = 0; i < characterReplacements.length; i++) {
char originalChar = (char) i;
char replacementChar = Character.toLowerCase(originalChar);
characterReplacements[i] = new CharacterReplacementPair(originalChar, replacementChar);
}
// Add these replacements to the index's dictionary.
index.getDictionaries().getCharacterReplacements().addRange(characterReplacements);
ドキュメントのインデックス作成
Now that the index is ready, you can add documents to index from any folder.
手順 3: インデックス作成のためにドキュメントを追加
GroupDocs.Search scans the target directory, extracts text from each supported file type, applies the replacement map, and writes the tokens to the index storage.
import com.groupdocs.search.Index;
String documentFolder = "YOUR_DOCUMENT_DIRECTORY";
// Initialize the index and add documents.
Index index = new Index(indexFolder, settings);
index.add(documentFolder);
大文字小文字を区別した検索の実行(オプション)
手順 4: 大文字小文字を区別した検索の実行
SearchOptions configures query behavior, such as toggling case sensitivity, allowing fine‑grained control over how searches are performed.SearchOptions.setUseCaseSensitiveSearch(true) forces the engine to treat upper‑ and lower‑case characters as distinct during a specific query, overriding the default case‑insensitive behavior.
import com.groupdocs.search.Index;
import com.groupdocs.search.SearchOptions;
import com.groupdocs.search.results.SearchResult;
String query = "Promotion";
SearchOptions options = new SearchOptions();
options.setUseCaseSensitiveSearch(true);
// Perform the search.
Index index = new Index(indexFolder, settings);
SearchResult result = index.search(query, options);
実用的な活用例
- Marketing Campaigns – Normalize product names so sales teams can locate assets without worrying about case.
- Customer Support – Power help‑desk search boxes that return the right article whether the user types “login” or “Login”.
- E‑commerce Catalogs – Ensure shoppers find items regardless of how they type product titles, improving conversion rates.
パフォーマンス考慮事項
- Organize Source Files – A tidy folder hierarchy reduces the time spent scanning during the add documents to index step.
- Monitor Memory – Indexing large corpora can consume significant RAM; processing files in batches of 500 – 1 000 items keeps heap usage under control.
- Asynchronous Indexing – When supported, run indexing on a background thread to keep the UI responsive and avoid blocking user operations.
よくある問題とトラブルシューティング
| 症状 | 考えられる原因 | 対策 |
|---|---|---|
| 既知の語句で結果が返らない | 文字置換が有効になっていない | settings.setUseCharacterReplacements(true) が設定され、置換マップに必要な文字が含まれていることを確認してください。 |
| インデックス作成中のメモリ不足エラー | 一度に大量の大きなファイルをインデックスしようとしている | 小さいバッチでインデックスするか、JVMヒープを増やす(-Xmx4g)。 |
| 検索が予期せず大文字小文字を区別した結果を返す | SearchOptions.setUseCaseSensitiveSearch(true) が設定されていた | デフォルトの大文字小文字を区別しない動作にするため、削除するか false に設定してください。 |
| インデックスのロード時間が予想を超える | フォルダ構成が非効率的、または SSD が使用されていない | ファイルを再整理し、未使用のドキュメントを削除し、インデックスを高速 SSD に保存してください。 |
| 特殊文字が無視される | 置換マップに Unicode エントリが欠如している | “é”、 “ß”、 “ø” などの文字に対するマッピングを追加してください。 |
よくある質問
Q: インデックス作成時に特殊文字(例: “é”, “ß”)をどのように扱えばよいですか?
A: それらの文字を置換マップに含め、ASCII 等価文字にマッピングするか、検索要件に応じて変更せずに保持します。
Q: 文字置換を特定の言語に限定できますか?
A: はい。対象言語の文字だけを含むカスタム置換配列を作成し、辞書に追加する前に使用します。
Q: インデックスのロードに時間がかかる場合はどうすればよいですか?
A: フォルダ構造を最適化し、不要なファイルを削除し、インデックスを高速 SSD に保存します。増分インデックス作成もロード負荷を軽減します。
Q: インデックス作成後に文字置換を元に戻すことは可能ですか?
A: できません。置換はインデックスデータに組み込まれるため、設定を変更して再構築する必要があります。
Q: 詳細な API ドキュメントはどこで確認できますか?
A: 公式ドキュメントと API リファレンスに詳しい情報があります(下記リソースをご参照ください)。
リソース
最終更新日: 2026-07-31
テスト済みバージョン: GroupDocs.Search 25.4 for Java
作者: GroupDocs