วิธีเพิ่มโฟลเดอร์ไปยังดัชนีด้วย GroupDocs.Search ใน Java
หากคุณต้องการ java full text search ที่สามารถขยายได้ถึงระดับล้านเอกสาร คุณอยู่ในที่ที่ถูกต้อง ในบทเรียนนี้คุณจะได้เรียนรู้วิธี add folder to index ด้วย 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 full text search คืออะไรและทำไมจึงสำคัญ?
Java full text search แปลงเอกสารดิบให้เป็น inverted index ทำให้สามารถดึงข้อมูลใด ๆ ภายในวินาทีย่อยได้ ความสามารถนี้เป็นสิ่งจำเป็นสำหรับคลังเอกสารทางกฎหมาย, ห้องสมุดวิจัย, และฐานความรู้ขององค์กรที่ผู้ใช้คาดหวังผลลัพธ์ทันที นอกจากนี้ยังช่วยเพิ่มประสิทธิภาพการทำงานในแอปพลิเคชันสมัยใหม่
ทำไมต้องใช้ groupdocs.search สำหรับ java full text search?
GroupDocs.Search ให้การทำดัชนีและการดำเนินการค้นหาที่มีอัตราผ่านสูงพร้อมการบีบอัดในตัว รองรับ 50+ input and output formats—รวมถึง PDF, DOCX, EML, และ HTML—และสามารถประมวลผลเอกสารหลายร้อยหน้าโดยไม่ต้องโหลดไฟล์ทั้งหมดเข้าสู่หน่วยความจำ ทำให้ใช้หน่วยความจำไม่เกิน 200 MB สำหรับงานทั่วไป
ข้อกำหนดเบื้องต้น
- 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.
การตั้งค่า GroupDocs.Search สำหรับ 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>
ดาวน์โหลดโดยตรง
Alternatively, download the latest version from GroupDocs.Search for Java releases.
การรับใบอนุญาต
- Free trial – explore all features without commitment.
- Temporary license – extended testing period.
- Purchase – unlock full production capabilities.
การเริ่มต้นและการตั้งค่าพื้นฐาน
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!");
}
}
ดัชนีข้อความด้วยการบีบอัดแบบกำหนดเอง
ขั้นตอนที่ 1: กำหนดโฟลเดอร์ดัชนี
Choose a directory where the index files will reside:
String indexFolder = "YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\StoringTextOfIndexedDocuments";
ขั้นตอนที่ 2: กำหนดค่าการตั้งค่าดัชนี
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));
ขั้นตอนที่ 3: สร้างดัชนีด้วยการตั้งค่าที่กำหนดเอง
Instantiate the index using the configuration defined above:
Index index = new Index(indexFolder, settings);
System.out.println("Index created with high compression.");
วิธีเพิ่มโฟลเดอร์ไปยังดัชนี
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);
วิธีค้นหาเอกสารที่ถูกดัชนี
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.");
การประยุกต์ใช้งานจริง
Real‑world scenarios where java full text search shines:
- Legal document management – การดึงไฟล์คดีอย่างทันที
- Academic research libraries – การค้นหาเอกสารและวิทยานิพนธ์อย่างรวดเร็ว
- Enterprise knowledge bases – การเข้าถึงคู่มือและคำถามที่พบบ่อยอย่างรวดเร็ว
- Content management systems – การค้นหาเนื้อหาอย่างมีประสิทธิภาพสำหรับเว็บไซต์ขนาดใหญ่
- Customer service archives – การค้นหาอย่างรวดเร็วของตั๋วและแชทที่ผ่านมา
ปัจจัยที่ต้องพิจารณาด้านประสิทธิภาพ
- 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.
ข้อผิดพลาดทั่วไป & เคล็ดลับมืออาชีพ
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.
คำถามที่พบบ่อย
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.
แหล่งข้อมูลเพิ่มเติม
- Detailed usage guide: GroupDocs Search Documentation
- Full API reference: API Reference Guide
- Stay up‑to‑date with new features: Latest Releases
อัปเดตล่าสุด: 2026-11-02
ทดสอบด้วย: GroupDocs.Search 25.4
ผู้เขียน: GroupDocs
String query = "sample";
import com.groupdocs.search.results.SearchResult;
SearchResult result = index.search(query);
System.out.println("Search completed. Results found: " + result.getDocumentCount());