Java 인덱싱 방법 – GroupDocs를 이용한 빠른 문서 검색
If you’re wondering how to index java files efficiently, you’re in the right place. In today’s data‑driven world, quickly locating the right document can save hours of manual work. GroupDocs.Search for Java gives you a straightforward way to turn a folder of files into a searchable index, letting you add documents to index, delete documents from index, and load documents from filesystem with just a few lines of code. This tutorial walks you through setup, indexing, searching, and clean‑up so you can integrate fast document search into any Java application.
빠른 답변
- 주요 목적은 무엇입니까? Java 문서를 효율적으로 인덱싱하고 검색합니다.
- 필요한 라이브러리는 무엇입니까? GroupDocs.Search for Java (v25.4+).
- 라이선스가 필요합니까? 무료 체험 또는 임시 라이선스를 사용할 수 있으며, 프로덕션에서는 영구 라이선스가 필요합니다.
- 인덱스에서 문서를 삭제할 수 있습니까? 예,
delete메서드를 사용하여 문서 키로 삭제할 수 있습니다. - Apache Commons IO가 필수입니까? 파일 처리 유틸리티를 위해 권장됩니다.
“how to index java”란 무엇입니까?
Indexing Java documents means creating a searchable data structure (an index) that maps document content to searchable terms, allowing rapid retrieval of relevant files based on keyword queries. By building this index once, subsequent searches run in milliseconds even across thousands of files, dramatically improving developer productivity and end‑user experience.
왜 GroupDocs.Search for Java를 사용합니까?
GroupDocs.Search supports 50+ input and output formats—including PDF, DOCX, XLSX, PPTX, HTML, and common image types—and can process multi‑hundred‑page documents without loading the entire file into memory. Its optimized algorithms deliver query responses in under 100 ms for datasets of up to 1 million documents, making it a scalable choice for enterprise‑grade search solutions.
전제 조건
Before we begin, make sure you have:
- GroupDocs.Search for Java (버전 25.4 이상).
- Apache Commons IO 파일 유틸리티를 위해.
- JDK 8 이상 및 IntelliJ IDEA 또는 Eclipse와 같은 IDE.
- 기본 Java 지식 및 선택적으로 Maven에 대한 친숙함.
GroupDocs.Search for Java 설정
Maven 구성
Add the 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>
팁: 최신 릴리스와 버전 번호를 동기화하여 성능 향상의 이점을 얻으세요.
직접 다운로드 (Maven을 사용하지 않으려는 경우)
공식 사이트에서 최신 JAR를 다운로드할 수도 있습니다: GroupDocs.Search for Java releases.
라이선스 획득
- 무료 체험: 라이선스 키 없이 라이브러리를 테스트합니다.
- 임시 라이선스: 장기 평가를 위해 요청합니다.
- 정식 라이선스: 프로덕션 배포에 필요합니다.
기본 초기화
라이브러리가 올바르게 로드되는지 확인하기 위해 간단한 Java 클래스를 생성합니다:
import com.groupdocs.search.*;
public class DocumentIndexing {
public static void main(String[] args) {
Index index = new Index("YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\DeleteIndexedDocuments");
System.out.println("GroupDocs.Search initialized successfully.");
}
}
이 프로그램을 실행하면 확인 메시지가 출력되어 인덱스 폴더가 준비되었음을 나타냅니다.
인덱스에 문서 추가 방법
The Document class represents a searchable entity that holds the file’s binary content and metadata.
To add a document, create a Document instance that wraps the file’s bytes and assigns a unique key, then call index.add(document). The library extracts the text, tokenizes it, and stores the postings in the index folder automatically. This operation runs in linear time relative to the file size and supports lazy loading for large files.
Direct answer:
Index index = new Index("YOUR_DOCUMENT_DIRECTORY\\output\\AdvancedUsage\\Indexing\\DeleteIndexedDocuments", true);
- The first argument is the folder where the index files will be stored.
- The second argument (
true) tells GroupDocs to create the folder if it doesn’t exist and to update an existing index automatically.
String filePath = "YOUR_DOCUMENT_DIRECTORY\\English.docx";
DocumentLoader documentLoader = new DocumentLoader(filePath);
Document document = Document.createLazy(DocumentSourceKind.Stream, documentLoader.getDocumentKey(), documentLoader);
Document[] documents = new Document[]{document};
index.add(documents, new IndexingOptions());
DocumentLoader(defined later) reads the file and provides a unique key.createLazyensures large files are processed efficiently, loading content only when needed.
파일 시스템에서 문서 로드 방법
The DocumentLoader utility class reads a file from disk and creates a corresponding Document object with a stable identifier.
To load files, the loader reads the file’s bytes, generates a unique key (for example, a hash of the path), and constructs a Document instance. This object can then be passed to index.add(document). Using a dedicated loader isolates file‑system concerns, making the indexing code reusable and easier to test across different storage back‑ends.
Direct answer:
class DocumentLoader {
private final String filePath;
private final String documentKey;
public DocumentLoader(String filePath) {
this.filePath = filePath;
documentKey = FilenameUtils.getName(filePath);
}
public String getDocumentKey() { return documentKey; }
public Document loadDocument() throws IOException {
Path path = Paths.get(filePath);
byte[] buffer = Files.readAllBytes(path);
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
return Document.createFromStream(documentKey, new Date(System.currentTimeMillis()), "." + FilenameUtils.getExtension(filePath), stream);
}
}
인덱스에서 키워드 검색 수행 방법
The SearchQuery class encapsulates the user’s query string, while SearchResult holds the matching document IDs, snippets, and relevance scores.
Create a SearchQuery with the desired keywords and optionally configure fuzzy matching or filters, then invoke index.search(query). The method returns a SearchResult object containing each matching document’s identifier, highlighted excerpts, and a relevance score. You can iterate over these results to display snippets or further process the matches.
Direct answer:
String query = "moment";
SearchResult searchResult1 = index.search(query);
- Pass any text string to
searchand receive aSearchResultcontaining matching document IDs, snippets, and relevance scores.
인덱스에서 문서 삭제 방법
The UpdateOptions class lets you control how changes such as deletions are applied to the index.
Provide the unique document keys to index.delete(keys), and the library removes all postings associated with those keys. You can pass an UpdateOptions instance to specify whether deletions are applied immediately or batched for better performance. After deletion, the index remains consistent without requiring a full rebuild.
Direct answer:
String[] documentKeys = new String[]{documentLoader.getDocumentKey()};
DeleteResult deleteResult = index.delete(new UpdateOptions(), documentKeys);
- Provide the keys of the documents you want to remove.
UpdateOptionslets you control how the deletion is applied (e.g., immediate vs. batch).
삭제 후 인덱스된 문서 조회 방법
The getDocumentList() method returns a collection of all document identifiers currently stored in the index.
Calling index.getDocumentList() provides the current set of document keys, reflecting all additions and deletions performed so far. This list can be used to verify that unwanted entries have been successfully removed or to iterate over remaining documents for further processing. It is a lightweight operation that does not modify the index.
Direct answer:
DocumentInfo[] indexedDocuments2 = index.getIndexedDocuments();
- This call returns the current list of documents still present in the index, helping you verify that deletions succeeded.
Java 검색 성능 팁
Optimizing java search performance involves three key actions: (1) run index.optimize() after bulk inserts or deletions to compact posting files, (2) enable lazy loading for files larger than 10 MB to avoid OutOfMemory errors, and (3) allocate sufficient JVM heap (e.g., -Xmx2g for medium‑scale workloads). Following these practices keeps query latency below 100 ms even as the index grows.
실용적인 적용 사례
- 기업 문서 포털 – 직원들이 정책, 계약서 또는 매뉴얼을 몇 초 만에 찾을 수 있습니다.
- 법률 사건 관리 – 변호사들이 수천 개의 PDF 및 Word 파일에서 선례 조항을 빠르게 찾을 수 있습니다.
- 디지털 라이브러리 – 대학이 연구 논문 및 학위 논문에 대한 전체 텍스트 검색을 제공합니다.
일반적인 문제 및 해결책
| 문제 | 원인 | 해결책 |
|---|---|---|
| 결과가 반환되지 않음 | 쿼리 용어가 인덱싱되지 않았거나 불용어가 필터링됨 | IndexingOptions를 확인하고 불용어 목록을 조정하십시오 |
| 메모리 부족 오류 | 큰 파일을 즉시 로드함 | Document.createLazy로 전환하거나 JVM 힙을 늘리십시오 |
| 삭제된 문서가 여전히 표시됨 | 삭제 후 인덱스가 새로 고쳐지지 않음 | index.optimize()를 호출하거나 인덱스 인스턴스를 다시 열십시오 |
자주 묻는 질문
Q: PDFs, DOCX, 그리고 PPTX를 함께 인덱싱할 수 있나요?
A: 예, GroupDocs.Search는 추가 변환기 없이 50개 이상의 파일 형식을 지원합니다.
Q: “인덱스에서 문서 삭제”가 내부적으로 어떻게 작동하나요?
A: delete 메서드는 지정된 문서 키에 대한 포스팅을 제거하고 내부 구조를 업데이트하여 전체 재구축 없이 인덱스가 일관성을 유지합니다.
Q: 인덱스 크기를 모니터링할 방법이 있나요?
A: index.getStatistics()를 사용하여 문서 수, 총 크기 및 기타 유용한 메트릭을 가져올 수 있습니다.
Q: 각 삭제 후 전체 인덱스를 재구축해야 하나요?
A: 아니요. 삭제는 증분 방식이며 영향을 받은 항목만 제거됩니다. index.optimize()를 주기적으로 호출하면 성능을 최적화할 수 있습니다.
Q: 스키마 변경 후 모든 파일을 다시 인덱싱해야 하면 어떻게 해야 하나요?
A: 다른 폴더를 가리키는 새 Index 인스턴스를 생성하고 모든 문서를 다시 추가한 뒤, 애플리케이션을 새 인덱스 경로로 전환하면 됩니다.
결론
You now have a complete roadmap for how to index java documents using GroupDocs.Search for Java—from setting up the environment, adding documents to index, loading them from the filesystem, performing searches, to deleting and verifying index contents. By integrating these steps into your application, you’ll dramatically improve document discoverability, cut search latency, and boost overall productivity.
다음 단계:
- 복잡한 쿼리(와일드카드, 퍼지 매칭) 실험하기.
- 페이시드 검색, 사용자 정의 분석기, 메타데이터 인덱싱과 같은 고급 기능 탐색하기.
인덱싱을 즐기세요!
Last Updated: 2026-08-05
Tested With: GroupDocs.Search Java 25.4
Author: GroupDocs