2026-02-16" keep.
“Tested With: GroupDocs.Search 25.4 for Java” keep.
“Author: GroupDocs” keep.
Now produce final content with Thai translation.
Need to ensure we keep markdown formatting exactly.
Let’s construct final answer.# Boolean Operators Java – สร้าง Search Index & Faceted Search
การนำ search experience ที่ทรงพลังใน Java ไปใช้สามารถรู้สึกท่วมท้นได้, โดยเฉพาะเมื่อคุณต้อง create a search index Java ที่รองรับ boolean operators Java สำหรับการค้นหาแบบ faceted และคำค้นหาที่ซับซ้อน ในบทแนะนำนี้เราจะพาคุณผ่านการตั้งค่า GroupDocs.Search for Java, การสร้างดัชนี, การเพิ่มเอกสาร, และการสร้างการค้นหา faceted แบบง่ายและคำค้นหาที่ซับซ้อนหลายเกณฑ์ที่ใช้ตรรกะ Boolean. เมื่อจบคุณจะเข้าใจวิธีใช้ content search Java, filename search Java, และแม้กระทั่งการทำงาน update index java เพื่อให้ข้อมูลของคุณสดใหม่.
Quick Answers
- What is a faceted search? วิธีการกรองผลลัพธ์โดยใช้หมวดหมู่ที่กำหนดไว้ล่วงหน้า เช่น ประเภทไฟล์หรือวันที่.
- How do I create a search index Java? เริ่มต้นอ็อบเจกต์
Indexที่ชี้ไปยังโฟลเดอร์และเพิ่มเอกสาร. - Can I combine multiple criteria with boolean operators? ใช่—ใช้ object‑based queries หรือ Boolean operators ในข้อความค้นหา.
- Do I need a license? การทดลองใช้งานฟรีทำงานได้สำหรับการพัฒนา; ไลเซนส์เชิงพาณิชย์จะลบข้อจำกัดทั้งหมด.
- Which IDE works best? IDE Java ใดก็ได้ (IntelliJ IDEA, Eclipse, NetBeans) ทำงานได้ดี.
What is “create search index java”?
การสร้าง search index ใน Java หมายถึงการสร้างโครงสร้างข้อมูลที่สามารถค้นหาได้ซึ่งเก็บเมตาดาต้าและเนื้อหาเอกสาร, ทำให้การดึงข้อมูลอย่างรวดเร็วตามคำค้นของผู้ใช้เป็นไปได้. ด้วย GroupDocs.Search, ดัชนีจะอยู่บนดิสก์, สามารถอัปเดตแบบเพิ่มส่วนได้, และรองรับคุณลักษณะขั้นสูงเช่น faceting, boolean operators Java, และตรรกะ Boolean ที่ซับซ้อน.
Why use GroupDocs.Search for faceted and complex queries?
- Out‑of‑the‑box faceting – กรองตามฟิลด์เช่นชื่อไฟล์, ขนาด, หรือเมตาดาต้ากำหนดเอง.
- Rich query language – ผสมผสานการค้นหาแบบข้อความ, วลี, และฟิลด์โดยใช้ตัวดำเนินการ AND/OR/NOT (หัวใจของ boolean operators java).
- Scalable performance – ดัชนีหลายล้านเอกสารพร้อมรักษาความหน่วงเวลาให้ต่ำ.
- Pure Java – ไม่มีการพึ่งพา native, ทำงานบนแพลตฟอร์มใดก็ได้ที่รัน JDK 8+.
- Easy index maintenance – เรียก
index.update()เพื่อ update index java หลังจากเพิ่มหรือเอาไฟล์ออก.
Prerequisites
- JDK 8 หรือใหม่กว่า ที่ติดตั้งและกำหนดค่าใน IDE ของคุณ.
- Maven (หรือ Gradle) สำหรับการจัดการ dependencies.
- GroupDocs.Search for Java ≥ 25.4.
- ความคุ้นเคยพื้นฐานกับแนวคิด OOP ของ Java และโครงสร้างโครงการ Maven.
Setting Up GroupDocs.Search for Java
Maven Setup
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 the official release page:
GroupDocs.Search for Java releases
License Acquisition
To unlock full functionality:
- Free trial – เหมาะสำหรับการพัฒนาและการทดสอบ.
- Temporary evaluation license – ขยายขีดจำกัดของการทดลอง.
- Commercial license – ลบข้อจำกัดทั้งหมดสำหรับการใช้งานในสภาพแวดล้อมการผลิต.
Basic Initialization and Setup
The following snippet shows how to create a search index Java by instantiating the Index class:
import com.groupdocs.search.Index;
public class SearchSetup {
public static void main(String[] args) {
String indexFolder = "YOUR_OUTPUT_DIRECTORY/AdvancedUsage/Searching/FacetedSearch/SimpleFacetedSearch";
// Create an instance of Index – this creates the on‑disk index
Index index = new Index(indexFolder);
System.out.println("GroupDocs.Search initialized successfully!");
}
}
With the index ready, we can move on to real‑world faceted and complex queries.
How to use boolean operators java – Simple Faceted Search
Faceted search lets end‑users narrow results by selecting values from predefined categories (facets). Below is a step‑by‑step walk‑through.
Step 1: Create an Index
First, point the Index to a folder where the index files will be stored.
import com.groupdocs.search.Index;
String indexFolder = "YOUR_OUTPUT_DIRECTORY/AdvancedUsage/Searching/FacetedSearch/SimpleFacetedSearch";
Index index = new Index(indexFolder);
Step 2: Add Documents to the Index
Tell GroupDocs.Search where your source documents live. All supported file types (PDF, DOCX, TXT, etc.) will be indexed automatically.
import com.groupdocs.search.Index;
String documentsFolder = "YOUR_DOCUMENT_DIRECTORY";
// Adding documents to the index
index.add(documentsFolder);
Step 3: Perform a Search in the Content Field with a Text Query
A quick text query filters by the content field. The syntax content: Pellentesque limits results to documents containing the word Pellentesque in their body text.
import com.groupdocs.search.results.SearchResult;
String query1 = "content: Pellentesque";
SearchResult result1 = index.search(query1);
// Output search results
System.out.println("Documents found (query 1): " + result1.getDocumentCount());
Step 4: Perform a Search Using an Object Query
Object‑based queries give you fine‑grained control. Here we build a word query, wrap it in a field query, and execute it.
import com.groupdocs.search.SearchQuery;
import com.groupdocs.search.options.CommonFieldNames;
SearchQuery wordQuery = SearchQuery.createWordQuery("Pellentesque");
SearchQuery fieldQuery = SearchQuery.createFieldQuery(CommonFieldNames.Content, wordQuery);
SearchResult result2 = index.search(fieldQuery);
// Output search results
System.out.println("Documents found (query 2): " + result2.getDocumentCount());
How to use boolean operators java – Complex Query Search
Complex queries combine multiple fields, Boolean operators, and phrase searches. This is ideal for scenarios like e‑commerce filters or legal document research.
Step 1: Create an Index for Complex Queries
Reuse the same folder structure; you can share the index across both simple and complex scenarios.
String indexFolder = "YOUR_OUTPUT_DIRECTORY/AdvancedUsage/Searching/FacetedSearch/ComplexQuery";
Index index = new Index(indexFolder);
index.add(documentsFolder);
Step 2: Perform a Search with a Text Query
The following query looks for files named lorem and ipsum or content containing either of two exact phrases.
import com.groupdocs.search.results.SearchResult;
String query1 = "(filename: (lorem AND ipsum)) OR (content: (\"lectus eu aliquam\" OR \"dignissim turpis\"))";
SearchResult result1 = index.search(query1);
// Output search results
class SearchResult {
public int getDocumentCount() {
// Implementation here
return 0; // Placeholder
}
}
System.out.println("Documents found (complex text query): " + result1.getDocumentCount());
Step 3: Perform a Search with an Object Query
Object‑based construction mirrors the textual query but offers type safety and IDE assistance.
import com.groupdocs.search.SearchQuery;
SearchQuery word6Query = SearchQuery.createWordQuery("lorem");
SearchQuery word7Query = SearchQuery.createWordQuery("ipsum");
// Constructing AND, OR queries for filename field
SearchQuery andQuery = SearchQuery.createAndQuery(word6Query, word7Query);
SearchQuery filenameQuery = SearchQuery.createFieldQuery(CommonFieldNames.FileName, andQuery);
// Content search using OR query with phrases
SearchQuery phrase1Query = SearchQuery.createPhraseSearchQuery("lectus", "eu", "aliquam");
SearchQuery phrase2Query = SearchQuery.createPhraseSearchQuery("dignissim", "turpis");
SearchQuery contentQuery = SearchQuery.createFieldQuery(CommonFieldNames.Content,
SearchQuery.createOrQuery(phrase1Query, phrase2Query));
// Final root query combining filename and content queries
SearchQuery rootQuery = SearchQuery.createOrQuery(filenameQuery, contentQuery);
SearchResult result2 = index.search(rootQuery);
// Output search results
System.out.println("Documents found (complex object query): " + result2.getDocumentCount());
Practical Applications of Faceted & Complex Searches
| สถานการณ์ | วิธีที่ Faceting ช่วย | ตัวอย่าง Query |
|---|---|---|
| E‑commerce catalog | กรองตามหมวดหมู่, ราคา, ยี่ห้อ | category: Electronics AND price:[100 TO 500] |
| Legal document repository | จำกัดโดยหมายเลขคดี, เขตอำนาจ | caseNumber: 2023-045 AND jurisdiction: "California" |
| Research archives | รวมผู้เขียน, ปีการตีพิมพ์, คำสำคัญ | (author: "Doe") AND (year: 2022) AND (keywords: "machine learning") |
| Enterprise intranet | ค้นหาตามประเภทไฟล์และแผนก | filetype: pdf AND department: HR |
These examples illustrate why mastering boolean operators java and filename search java techniques is a game‑changer for any data‑intensive application.
Common Pitfalls & Troubleshooting
- Empty results – ตรวจสอบว่าเอกสารถูกเพิ่มสำเร็จ (
index.getDocumentCount()สามารถช่วยได้). - Stale index – หลังจากเพิ่มหรือเอาไฟล์ออก, เรียก
index.update()เพื่อ update index java และทำให้ดัชนีสอดคล้อง. - Incorrect field names – ใช้ค่าสถิต
CommonFieldNames(Content,FileName, ฯลฯ) เพื่อหลีกเลี่ยงการพิมพ์ผิด. - Performance bottlenecks – สำหรับคอลเลกชันขนาดใหญ่, พิจารณาเปิดใช้งาน
index.setCacheSize()หรือใช้ SSD เฉพาะสำหรับโฟลเดอร์ดัชนี. - Missing highlights – เพื่อ highlight search results java, ดึงส่วนที่ตรงกันผ่าน
SearchResult.getFragments()(ไม่ได้แสดงในที่นี้แต่มีใน API).
Frequently Asked Questions
Q: Can I use GroupDocs.Search with Spring Boot?
A: Absolutely. Add the Maven dependency, configure the index as a Spring bean, and inject it wherever you need search capabilities.
Q: Does the library support custom metadata fields?
A: Yes – you can add user‑defined fields during indexing and then facet on them.
Q: How large can the index grow?
A: The index is disk‑based and can handle millions of documents; just ensure sufficient storage and monitor cache settings.
Q: Is there a way to rank results by relevance?
A: GroupDocs.Search automatically scores matches; you can retrieve the score via SearchResult.getDocument(i).getScore().
Q: What happens if I index encrypted PDFs?
A: Provide the password when adding the document: index.add(filePath, password).
Conclusion
By now you should feel comfortable creating a search index Java with GroupDocs.Search, adding documents, and crafting both simple faceted queries and sophisticated Boolean searches using boolean operators java. These capabilities empower you to deliver fast, accurate, and user‑friendly search experiences across a wide range of applications—from e‑commerce platforms to enterprise knowledge bases.
Ready for the next step? Explore GroupDocs.Search’s advanced features such as highlighting, suggestions, and real‑time indexing to further boost your application’s search power.
Last Updated: 2026-02-16
Tested With: GroupDocs.Search 25.4 for Java
Author: GroupDocs