Class LuceneSearchService

java.lang.Object
com.easydesk.lucene.LuceneSearchService
All Implemented Interfaces:
IndexConstants, Searchable, SearchService

public class LuceneSearchService extends Object implements SearchService
Spring 기반 Lucene Search Service.

기존 Avalon 기반 BaseLuceneSearchService / DefaultOMSearchService 를 대체한다.

  • Configurable.configure(Configuration) → 생성자 / setter (easydesk.lucene.* property 는 LuceneConfig 에서 주입)
  • Initializable.initialize() → PostConstruct
  • Disposable.dispose() → PreDestroy
  • RAMDirectory + Flusher/Worker thread → index location 별 LuceneIndex (IndexWriter + near-real-time SearcherManager) 와 주기적인 commit() (Scheduled)
  • Lucene Filter (module filter) → BooleanClause.Occur.FILTER clause
  • RMI Remote Server mode 는 제거되었다. (Spring 6 에서 RMI 지원 제거, Lucene Document 는 Serializable 이 아님)
Index 는 indexLocation 아래 상대 경로 (예: 3/attribute/12) 별로 독립된 Lucene index 로 관리된다.
Author:
조 영 호
  • Field Details

    • DEFAULT_ANALYZER

      public static final String DEFAULT_ANALYZER
      Default analyzer class
      See Also:
    • WILDCARD

      public static final String WILDCARD
      index location wildcard : 경로 한 단계와 일치한다. (예: */attribute/12 는 모든 module 의 itemType 12)
      See Also:
  • Constructor Details

    • LuceneSearchService

      public LuceneSearchService(Path indexLocation, org.apache.lucene.analysis.Analyzer analyzer)
      Creates a new LuceneSearchService.
      Parameters:
      indexLocation - index root directory
      analyzer - analyzer
  • Method Details

    • createAnalyzer

      public static org.apache.lucene.analysis.Analyzer createAnalyzer(String className)
      Analyzer class 이름으로 analyzer 를 만든다. (no-arg constructor 필요)
      Parameters:
      className - analyzer class name
      Returns:
      analyzer
    • setRamBufferSizeMB

      public void setRamBufferSizeMB(double ramBufferSizeMB)
      Parameters:
      ramBufferSizeMB - IndexWriter RAM buffer size (MB)
    • setRecreateIncompatibleIndex

      public void setRecreateIncompatibleIndex(boolean recreateIncompatibleIndex)
      Parameters:
      recreateIncompatibleIndex - true 이면 이전 Lucene version (예: 4.x) 으로 만들어진 index 의 file 을 삭제하고 빈 index 를 새로 만든다. (re-index 필요)
    • setSlowSearchThreshold

      public void setSlowSearchThreshold(long slowSearchThreshold)
      Parameters:
      slowSearchThreshold - 이 시간(msec) 보다 오래 걸린 검색은 WARN log 를 남긴다.
    • getIndexLocation

      public Path getIndexLocation()
      Returns:
      index root directory
    • getAnalyzer

      public org.apache.lucene.analysis.Analyzer getAnalyzer()
      Description copied from interface: SearchService
      검색과 index 에 사용하는 Analyzer
      Specified by:
      getAnalyzer in interface SearchService
      Returns:
      analyzer
    • getLocations

      public Set<String> getLocations()
      Returns:
      열려 있는 index location 목록
    • getIndex

      public LuceneIndex getIndex(String location)
      Parameters:
      location - index location
      Returns:
      열려 있는 index, 없으면 null
    • initialize

      @PostConstruct public void initialize() throws IOException
      index root 아래의 index 들을 연다.
      Throws:
      IOException - 오류
    • close

      @PreDestroy public void close()
      모든 index 를 commit 하고 닫는다.
    • search

      public BitSet search(QueryInfo[] info, BitSet moduleFilter, String[] path) throws IOException
      Description copied from interface: Searchable
      search item
      Specified by:
      search in interface Searchable
      Parameters:
      info - query 정보
      moduleFilter - 검색이 허용된 module id 의 BitSet. null 이면 module filter 를 적용하지 않고, 비어 있으면 검색이 허용된 module 이 없으므로 결과가 없다. (기존 BitVector 를 대체)
      path - index path (index root 기준 상대 경로) 배열. * 는 경로 한 단계와 일치한다. (예: 모든 module 의 itemType 12 attribute index : */attribute/12)
      Returns:
      IndexConstants.ITEM_ID 를 수집한 BitSet
      Throws:
      IOException - search engine 오류
    • match

      public Set<String> match(String pattern)
      열려 있는 index location 중 wildcard pattern 에 맞는 것을 구한다. * 는 경로 한 단계 (segment) 와 일치한다.
      Parameters:
      pattern - 예: */attribute/12
      Returns:
      matched locations
    • search

      public BitSet search(org.apache.lucene.search.Query query, String[] path) throws IOException
      주어진 index 들에서 query 로 검색하여 IndexConstants.ITEM_ID 를 수집한다.
      Parameters:
      query - query
      path - index location 배열
      Returns:
      수집된 ITEM_ID
      Throws:
      IOException - 오류
    • addDocument

      public void addDocument(Indexable doc) throws IOException
      Description copied from interface: Searchable
      document 를 index 에 추가(교체)한다. Indexable.getDocument() 가 null 이면 제거한다.
      Specified by:
      addDocument in interface Searchable
      Parameters:
      doc - index 대상
      Throws:
      IOException - index 오류
    • isLocal

      public boolean isLocal()
      Description copied from interface: Searchable
      서버가 Local 인지 아니면 Remote 인지
      Specified by:
      isLocal in interface Searchable
      Returns:
      local 이면 true
    • scheduledCommit

      @Scheduled(fixedDelayString="${easydesk.lucene.commit-period:60000}", initialDelayString="${easydesk.lucene.commit-period:60000}") public void scheduledCommit()
      변경된 내용을 주기적으로 commit 한다. (easydesk.lucene.commit-period, 기본 60초)
    • commit

      public void commit() throws IOException
      Description copied from interface: SearchService
      변경된 내용을 모든 index 에 commit 한다.
      Specified by:
      commit in interface SearchService
      Throws:
      IOException - index 오류
    • refresh

      public void refresh() throws IOException
      변경된 내용을 즉시 검색에 반영한다. (보통은 검색할 때 자동으로 반영된다.)
      Throws:
      IOException - 오류
    • deleteAll

      public void deleteAll() throws IOException
      Description copied from interface: SearchService
      모든 index 의 document 를 지우고 commit 한다. (re-index 전에 사용)
      Specified by:
      deleteAll in interface SearchService
      Throws:
      IOException - index 오류
    • optimize

      public void optimize() throws IOException
      Description copied from interface: SearchService
      Index 를 Optimize (segment 를 하나로 merge) 한다. 비용이 큰 작업이므로 운영 중에는 주의하여 사용한다.
      Specified by:
      optimize in interface SearchService
      Throws:
      IOException - index 오류
    • backup

      public Path backup() throws IOException
      Description copied from interface: SearchService
      Index 를 index root 옆의 lucene_yyyy-MM-dd directory 로 backup 한다.
      Specified by:
      backup in interface SearchService
      Returns:
      backup directory
      Throws:
      IOException - index 오류
    • toKey

      protected String toKey(String location)
      index location 을 index root 기준의 정규화된 상대 경로로 만든다.
      Parameters:
      location - 상대 경로 또는 index root 아래의 절대 경로. index root 밖의 절대 경로는 root 를 제외한 경로를 상대 경로로 사용한다. (기존 BaseLuceneSearchService.getIndexLocation 과 동일)
      Returns:
      key (/ 구분자)