使用 GroupDocs.Search for Java 建立搜尋索引 GroupDocs - 完整指南
介紹
如果您需要在 Java 應用程式中 create search index groupdocs,您來對地方了。在本教學中,我們將逐步說明設定 GroupDocs.Search、建立索引、加入檔案以及擷取文件文字的完整流程——所有程式碼皆可直接複製到您的專案中。完成後,您將清楚了解 how to index documents java 的作法,並能將強大的搜尋功能整合至任何企業解決方案。
快速回答
- What is the primary purpose of GroupDocs.Search?
為在 Java 中提供快速、全文索引與檢索,支援多種文件格式。 - Which library version is recommended?
推薦使用最新的穩定版(例如撰寫時的 25.4 版)。 - Do I need a license to run the examples?
可取得臨時授權以進行評估;正式環境需購買商業授權。 - What are the main steps to create a search index?
安裝函式庫、設定索引參數、加入文件、以及查詢索引。 - Can I store indexed text in compressed form?
可以 — 使用TextStorageSettings搭配Compression.High。
「create search index groupdocs」是什麼?
使用 GroupDocs 建立搜尋索引,即是構建一個可搜尋的資料結構,將文件中每個詞彙對應到其所在位置。這讓關鍵字即時查詢、片語搜尋以及進階篩選成為可能,無需每次都掃描原始檔案。
為什麼選擇 GroupDocs.Search for Java?
- Broad format support – 支援 PDF、Word、Excel、PowerPoint 等多種格式。
- High performance – 優化的索引演算法即使在百萬檔案下亦能保持低搜尋延遲。
- Easy integration – 簡潔的 Java API、基於 Maven 的相依管理,以及清晰的文件說明。
前置條件
必要的函式庫與相依性
- Java Development Kit (JDK) 8 或以上。
- Maven 用於相依管理。
環境設定需求
確保 Maven 已正確設定,以從 GroupDocs 儲存庫下載套件。
知識前提
具備基本的 Java 程式設計、檔案 I/O 操作經驗,以及對索引概念的了解,將有助於順利跟隨本教學。
設定 GroupDocs.Search for Java
Maven 設定
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>
直接下載
或者,從 GroupDocs.Search for Java releases 下載最新版本。
取得授權
您可前往其 Temporary License page 取得臨時授權,以在購買前完整體驗 GroupDocs 功能。此試用期允許您在自己的環境中評估此函式庫。
基本初始化與設定
Start by creating an Index object that points to the folder where the index files will be stored:
String indexFolder = "YOUR_INDEX_DIRECTORY";
Index index = new Index(indexFolder);
實作指南
如何使用 GroupDocs.Search 以 Java 索引文件
概觀
建立索引是啟用快速搜尋功能的第一步。以下將逐項說明每個必要的操作。
步驟 1:指定目錄
Define where the index will live and where the source documents are located.
String indexFolder = "YOUR_INDEX_DIRECTORY";
String documentsFolder = "YOUR_DOCUMENTS_DIRECTORY";
步驟 2:建立索引
Instantiate the Index object to begin building the searchable structure.
Index index = new Index(indexFolder);
步驟 3:將文件加入索引
Feed all files from the source folder into the index with a single call.
index.add(documentsFolder);
步驟 4:取得已索引的文件
Once indexing is complete you can enumerate the indexed entries:
DocumentInfo[] documents = index.getIndexedDocuments();
for (DocumentInfo document : documents) {
String filePath = document.getFilePath();
// Process each file path or perform further actions here
}
參數與方法目的
indexFolder:儲存索引資料的路徑。documentsFolder:包含待索引檔案的目錄。
除錯提示
- 確認資料夾路徑正確且可存取。
- 若在索引時遇到「access denied」錯誤,請檢查檔案系統權限。
使用文字儲存設定建立索引
概觀
您可以微調每份文件原始文字的儲存方式,例如啟用高壓縮以減少磁碟使用量。
步驟 1:設定索引參數
Create an IndexSettings instance and configure text storage.
IndexSettings settings = new IndexSettings();
settings.setTextStorageSettings(new TextStorageSettings(Compression.High));
步驟 2:以設定初始化索引
Pass the custom settings when constructing the index.
Index index = new Index(indexFolder, settings);
步驟 3:擷取並儲存文件文字
Extract the full text of a document and save it as HTML (or any supported format).
DocumentInfo[] documents = index.getIndexedDocuments();
if (documents.length > 0) {
String outputPath = "YOUR_OUTPUT_DIRECTORY/Text.html";
FileOutputAdapter outputAdapter = new FileOutputAdapter(OutputFormat.Html, outputPath);
index.getDocumentText(documents[0], outputAdapter);
}
關鍵設定選項
Compression.High– 透過壓縮擷取的文字來最佳化儲存空間。
實務應用
- Enterprise Document Management – 快速在龐大資料庫中定位合約、政策或報告。
- Content Management Systems (CMS) – 為全站搜尋提供即時結果。
- Legal Document Handling – 允許在案件檔案與證據庫中以關鍵字進行搜尋。
效能考量
- Optimizing Index Size – 定期清除過時條目,以維持索引精簡。
- Memory Management – 調整 JVM 的垃圾回收機制,以因應大規模索引工作。
- Best Practices – 以批次方式建立索引、重複使用
Index實例,並在大量工作負載時優先使用非同步操作。
結論
您現在已擁有一套完整、可投入生產的指南,說明如何使用 GroupDocs.Search for Java create search index groupdocs。依循上述步驟,即可為任何基於 Java 的解決方案加入快速且可靠的全文搜尋功能。探索進階查詢特性、與其他服務整合,並持續調整設定以符合您的效能目標。
後續步驟
- 嘗試進階查詢語法(萬用字元、模糊搜尋等)。
- 將 GroupDocs.Search 與 UI 框架結合,打造使用者友善的搜尋入口。
- 檢視官方 API 參考文件,以取得更多自訂化選項。
常見問題
- What is GroupDocs.Search for Java?
一個強大的函式庫,讓開發者能有效地在 Java 應用程式中加入全文搜尋功能。 - How do I handle large datasets with GroupDocs.Search?
使用批次處理並最佳化索引設定,以有效管理資源。 - Can I customize the compression level in text storage settings?
可以,您可設定如Compression.High或Compression.Low等不同的壓縮等級。 - What types of documents does GroupDocs.Search support?
支援多種格式,包括 PDF、Word、Excel、PowerPoint 以及其他許多檔案類型。 - Is there community support for GroupDocs.Search?
有,您可透過他們的論壇取得免費支援,網址為 GroupDocs Forum。
資源
- Documentation: https://docs.groupdocs.com/search/java/
- API Reference: https://reference.groupdocs.com/search/java
- Download: https://releases.groupdocs.com/search/java/
- GitHub Repository: https://github.com/groupdocs-search/GroupDocs.Search-for-Java
- Free Support Forum: https://forum.groupdocs.com/c/search/10
透過上述資源並嘗試不同設定,您可以進一步提升對 GroupDocs.Search for Java 的了解與運用。祝開發愉快!
Last Updated: 2026-01-01
Tested With: GroupDocs.Search 25.4
Author: GroupDocs