Let’s translate to Traditional Chinese.

Last Updated: 2026-03-15 -> “最後更新: 2026-03-15”

Tested With: GroupDocs.Search 25.4 -> “測試環境: GroupDocs.Search 25.4”

Author: GroupDocs -> “作者: GroupDocs”

Make sure bold formatting preserved.

Now final.

Make sure all markdown formatting preserved.

Now produce final content.# Java 全文搜尋:如何使用 GroupDocs.Search 索引文字

如果您需要能夠擴展至數百萬文件的 java full text search,您來對地方了。在本教學中,我們將逐步說明如何在 Java 環境中設定 GroupDocs.Search、配置高壓縮儲存、加入資料夾進行索引,以及執行閃電般快速的查詢。完成後,您將擁有可直接嵌入任何 Java 專案的生產級解決方案。

快速解答

  • 主要的函式庫是什麼? GroupDocs.Search for Java
  • 如何將資料夾加入索引? Use index.add(folderPath)
  • 我可以設定文字壓縮嗎? Yes, via TextStorageSettings(Compression.High)
  • 需要哪個 Java 版本? JDK 8 or higher
  • 在哪裡取得試用授權? From the GroupDocs website or the repository page

什麼是 Java 全文搜尋,以及它的重要性?

Java full text search 將原始文件轉換為可搜尋的結構,實現資訊的即時檢索。這對於法律檔案庫、研究圖書館以及企業知識庫等應用至關重要,因為使用者期望在毫秒級回應時間內取得查詢結果。

為什麼在 Java 全文搜尋中使用 GroupDocs.Search?

  • 高效能 – 最佳化的索引與查詢執行。
  • 內建壓縮 – 在不犧牲速度的前提下降低磁碟佔用。
  • 廣泛格式支援 – 開箱即用即可索引 PDF、Word 檔案、電子郵件等多種格式。
  • 簡易 API – 直觀的 Java 方法,可自然融入現有程式碼基礎。

前置條件

在開始之前,請確保您已具備:

  • GroupDocs.Search for Java(版本 25.4 或更新)
  • JDK 8+ 已安裝並設定
  • Maven 用於相依管理
  • IDE,例如 IntelliJ IDEA 或 Eclipse

設定 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 下載最新版本。

取得授權

  • Free Trial – 無需承諾即可體驗全部功能。
  • Temporary License – 延長測試期間。
  • Purchase – 解鎖完整的生產功能。

基本初始化與設定

Create a simple Java class to initialize the search engine:

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!");
    }
}

如何使用自訂壓縮索引文字

步驟 1:定義索引資料夾

Choose a directory where the index files will reside:

String indexFolder = "YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\StoringTextOfIndexedDocuments";

步驟 2:設定索引參數

Set up high‑compression text storage to reduce disk usage:

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));

步驟 3:使用自訂設定建立索引

Instantiate the index using the configuration defined above:

Index index = new Index(indexFolder, settings);
System.out.println("Index created with high compression.");

如何將資料夾加入索引

步驟 1:初始化索引(若尚未完成)

Assuming the index folder and settings are prepared:

String documentsFolder = "YOUR_DOCUMENT_DIRECTORY"; // Replace with actual document path.
Index index = new Index(indexFolder);

步驟 2:從資料夾加入文件

Index all supported files in the given directory:

index.add(documentsFolder);
System.out.println("Documents added successfully.");

如何搜尋已索引的文件

步驟 1:定義搜尋查詢

Specify the term you want to locate:

String query = "Lorem";  

步驟 2:執行搜尋

Run the query against the index and retrieve results:

import com.groupdocs.search.results.SearchResult;

SearchResult result = index.search(query);
System.out.println("Search completed. Results found: " + result.getDocumentCount());

實務應用

在實務情境中,java full text search 的應用亮點包括:

  1. Legal Document Management – 即時取得案件檔案。
  2. Academic Research Libraries – 快速查找論文與學位論文。
  3. Enterprise Knowledge Bases – 快速存取手冊與常見問答。
  4. Content Management Systems – 為大型網站提供高效的內容發現。
  5. Customer Service Archives – 快速搜尋過往工單與聊天記錄。

效能考量

  • Compression vs. Speed:高壓縮可節省空間,但在索引時可能會產生少量額外負擔。請針對您的工作負載測試兩種設定。
  • Memory Management:在索引極大規模語料庫時,請監控堆積使用情況。
  • Index Updates:定期加入新文件或刪除過時文件,以維持搜尋結果的相關性。
  • Query Optimization:利用 GroupDocs.Search 的進階查詢語法,以取得精確結果。

常見陷阱與專業提示

  • Pitfall: 忘記在大量新增後呼叫 index.optimize()
    Pro tip: 每晚執行 index.optimize() 以保持索引緊湊。

  • Pitfall: 在大規模資料集上使用預設(低)壓縮。
    Pro tip: 在生產環境中切換至 Compression.High 以降低儲存成本。

  • Pitfall: 從網路共享加入檔案時未處理 IOException
    Pro tip:index.add() 包裹於 try‑catch 區塊,並記錄失敗以供日後檢查。

常見問答

Q: GroupDocs.Search 是什麼?
A: 它是一個功能強大的 Java 函式庫,提供先進的全文搜尋功能,包括索引、壓縮與複雜查詢支援。

Q: 如何使用 GroupDocs.Search 處理大型資料集?
A: 啟用高壓縮 (Compression.High) 並定期提交變更以保持索引精簡。同時,配置足夠的堆積記憶體。

Q: 我可以將 GroupDocs.Search 整合至現有企業系統嗎?
A: 可以,該函式庫可嵌入任何基於 Java 的後端、REST 服務或微服務架構中。

Q: 如果我的索引變得過時該怎麼辦?
A: 使用 index.add() 方法新增檔案,使用 index.delete() 移除過時檔案,必要時重新執行 index.optimize()

Q: 我可以在哪裡取得協助或支援?
A: 前往 GroupDocs forums 社群論壇,尋求除錯與最佳實踐建議。

資源


最後更新: 2026-03-15
測試環境: GroupDocs.Search 25.4
作者: GroupDocs