Class LuceneIndex

java.lang.Object
com.easydesk.lucene.index.LuceneIndex
All Implemented Interfaces:
Closeable, AutoCloseable

public final class LuceneIndex extends Object implements Closeable
하나의 index location (directory) 에 대한 IndexWriter 와 near-real-time SearcherManager.

기존 MMapWrapper + RAMDirectoryWrapper + Flusher/Worker thread 조합을 대체한다. Lucene 의 near-real-time search 를 사용하므로 별도의 RAMDirectory 가 필요 없다.

이 class 는 thread-safe 하다.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.lucene.search.IndexSearcher
    검색용 IndexSearcher 를 얻는다.
    void
    backup(Path target)
    현재 commit point 를 target directory 로 복사한다.
    void
    변경된 내용을 commit 하고 닫는다.
    boolean
    변경된 내용이 있으면 commit 한다.
    void
    모든 document 를 지우고 commit 한다.
     
     
    org.apache.lucene.index.IndexWriter
     
    void
    변경된 내용을 검색에 반영한다.
    void
    변경된 내용을 검색에 반영한다.
    int
     
    open(String name, Path path, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.index.IndexWriterConfig.OpenMode openMode, double ramBufferSizeMB)
    index 를 연다.
    void
    segment 를 하나로 merge 하고 commit 한다.
    void
    release(org.apache.lucene.search.IndexSearcher searcher)
     
     
    void
    update(org.apache.lucene.index.Term term, org.apache.lucene.document.Document document)
    unique term 에 해당하는 document 를 교체한다.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 directory
      analyzer - analyzer
      openMode - open mode
      ramBufferSizeMB - IndexWriter RAM buffer size
      Returns:
      opened index
      Throws:
      IOException - open 오류 (IndexFormatTooOldException 포함)
    • getName

      public String getName()
      Returns:
      index root 기준 상대 경로
    • getPath

      public Path 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

      public void maybeRefresh() throws IOException
      변경된 내용을 검색에 반영한다. 다른 thread 가 refresh 중이면 기다리지 않는다.
      Throws:
      IOException - refresh 오류
    • maybeRefreshBlocking

      public void maybeRefreshBlocking() throws IOException
      변경된 내용을 검색에 반영한다. 다른 thread 가 refresh 중이면 기다린다.
      Throws:
      IOException - refresh 오류
    • acquire

      public org.apache.lucene.search.IndexSearcher acquire() throws IOException
      검색용 IndexSearcher 를 얻는다. 사용 후 반드시 release(IndexSearcher) 하여야 한다.
      Returns:
      searcher
      Throws:
      IOException - 오류
    • release

      public void release(org.apache.lucene.search.IndexSearcher searcher) throws IOException
      Parameters:
      searcher - acquire() 로 얻은 searcher
      Throws:
      IOException - 오류
    • commit

      public boolean commit() throws IOException
      변경된 내용이 있으면 commit 한다.
      Returns:
      commit 하였으면 true
      Throws:
      IOException - 오류
    • deleteAll

      public void deleteAll() throws IOException
      모든 document 를 지우고 commit 한다.
      Throws:
      IOException - 오류
    • optimize

      public void optimize() throws IOException
      segment 를 하나로 merge 하고 commit 한다.
      Throws:
      IOException - 오류
    • backup

      public void backup(Path target) throws IOException
      현재 commit point 를 target directory 로 복사한다. 복사하는 동안에도 index/search 는 계속 가능하다.
      Parameters:
      target - backup directory
      Throws:
      IOException - 오류
    • numDocs

      public int numDocs() throws IOException
      Returns:
      삭제되지 않은 document 수 (마지막 refresh 기준)
      Throws:
      IOException - 오류
    • close

      public void close() throws IOException
      변경된 내용을 commit 하고 닫는다.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class Object