2013-08-21 90 views

回答

3

是的,您需要重新打開閱讀器。

使用SearcherManager自動更新閱讀器,當您進行更改時調用maybeRefresh

樣品下面的Scala代碼:

@volatile protected var LAST_SEARCHER_REFRESH = 0 
protected lazy val SEARCHER_MANAGER = new SearcherManager (LUCENE_DIR, new SearcherFactory { 
    override def newSearcher (reader: IndexReader): IndexSearcher = {new IndexSearcher (reader)} 
}) 

... 

if (LAST_SEARCHER_REFRESH != Time.relativeSeconds()) {LAST_SEARCHER_REFRESH = Time.relativeSeconds(); SEARCHER_MANAGER.maybeRefresh()} 
val searcher = SEARCHER_MANAGER.acquire(); try { 
    searcher.search (query, collector) 
    ... 
} finally {SEARCHER_MANAGER.release (searcher)} 

有時候你必須雖然實現自己的緩存,像when you need to synchronize the IndexReader with TaxonomyReaderIndexSearcher description有關於如何做到這一點的建議(通過DirectoryReader.open(IndexWriter, applyAllDeletes)有一條快速路徑可用於從用於提交更改的編寫器創建新讀取器)。

相關問題