Package com.easydesk.lucene.index
Class LuceneIndex
java.lang.Object
com.easydesk.lucene.index.LuceneIndex
- All Implemented Interfaces:
Closeable,AutoCloseable
하나의 index location (directory) 에 대한
IndexWriter 와 near-real-time SearcherManager.
기존 MMapWrapper + RAMDirectoryWrapper + Flusher/Worker thread 조합을 대체한다. Lucene 의 near-real-time
search 를 사용하므로 별도의 RAMDirectory 가 필요 없다.
update(Term, Document): unique term 으로 기존 document 를 교체(atomic delete + add)maybeRefresh(): 변경된 내용을 검색에 반영 (commit 없이)commit(): 변경된 내용을 disk 에 영구 저장
-
Method Summary
Modifier and TypeMethodDescriptionorg.apache.lucene.search.IndexSearcheracquire()검색용 IndexSearcher 를 얻는다.void현재 commit point 를 target directory 로 복사한다.voidclose()변경된 내용을 commit 하고 닫는다.booleancommit()변경된 내용이 있으면 commit 한다.void모든 document 를 지우고 commit 한다.getName()getPath()org.apache.lucene.index.IndexWritervoid변경된 내용을 검색에 반영한다.void변경된 내용을 검색에 반영한다.intnumDocs()static LuceneIndexopen(String name, Path path, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.index.IndexWriterConfig.OpenMode openMode, double ramBufferSizeMB) index 를 연다.voidoptimize()segment 를 하나로 merge 하고 commit 한다.voidrelease(org.apache.lucene.search.IndexSearcher searcher) toString()voidupdate(org.apache.lucene.index.Term term, org.apache.lucene.document.Document document) unique term 에 해당하는 document 를 교체한다.
-
Method Details
-
open
public static LuceneIndex open(String name, Path path, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.index.IndexWriterConfig.OpenMode openMode, double ramBufferSizeMB) throws IOException index 를 연다. 존재하지 않으면 생성한다.- Parameters:
name- index root 기준 상대 경로path- index directoryanalyzer- analyzeropenMode- open moderamBufferSizeMB- IndexWriter RAM buffer size- Returns:
- opened index
- Throws:
IOException- open 오류 (IndexFormatTooOldException포함)
-
getName
- Returns:
- index root 기준 상대 경로
-
getPath
- Returns:
- index directory
-
getWriter
public org.apache.lucene.index.IndexWriter getWriter()- Returns:
- IndexWriter (직접 사용할 때 주의)
-
update
public void update(org.apache.lucene.index.Term term, org.apache.lucene.document.Document document) throws IOException unique term 에 해당하는 document 를 교체한다.- Parameters:
term- unique term,null이면 추가만 한다.document- document,null이면 term 에 해당하는 document 를 제거한다.- Throws:
IOException- index 오류
-
maybeRefresh
변경된 내용을 검색에 반영한다. 다른 thread 가 refresh 중이면 기다리지 않는다.- Throws:
IOException- refresh 오류
-
maybeRefreshBlocking
변경된 내용을 검색에 반영한다. 다른 thread 가 refresh 중이면 기다린다.- Throws:
IOException- refresh 오류
-
acquire
검색용 IndexSearcher 를 얻는다. 사용 후 반드시release(IndexSearcher)하여야 한다.- Returns:
- searcher
- Throws:
IOException- 오류
-
release
- Parameters:
searcher-acquire()로 얻은 searcher- Throws:
IOException- 오류
-
commit
변경된 내용이 있으면 commit 한다.- Returns:
- commit 하였으면 true
- Throws:
IOException- 오류
-
deleteAll
모든 document 를 지우고 commit 한다.- Throws:
IOException- 오류
-
optimize
segment 를 하나로 merge 하고 commit 한다.- Throws:
IOException- 오류
-
backup
현재 commit point 를 target directory 로 복사한다. 복사하는 동안에도 index/search 는 계속 가능하다.- Parameters:
target- backup directory- Throws:
IOException- 오류
-
numDocs
- Returns:
- 삭제되지 않은 document 수 (마지막 refresh 기준)
- Throws:
IOException- 오류
-
close
변경된 내용을 commit 하고 닫는다.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
toString
-