Lucene 3.0.0 之範例解析(3)-IndexFiles.java

來源:互聯網
上載者:User

一. consumer的來源

接著上一小節的內容, 還是從這一段程式(位於DocumentWriter.updateDocument(Document, Analyzer, Term) 中繼續.

try {
  // This call is not synchronized and does all the
  // work
  final DocWriter perDoc = state.consumer.processDocument();

  // This call is synchronized but fast
  finishDocument(state, perDoc);
  success = true;
}

第一句話就是產生索引的一個過程, 下面我將詳細的剖析這個過程.

首先一個問題就是:consumer是怎麼來的? 什麼時候初始化的, 我們用單步程式的方法來看看.

state是從上一節提到的

synchronized DocumentsWriterThreadState getThreadState(Document doc, Term delTerm)

中得到的, 我們進去看看... 原來是這一句話,

state = newArray[threadStates.length] = new DocumentsWriterThreadState(this);

跟蹤進去看看, DocumentWriterThreadState的建構函式, 發現了這一句:

consumer = docWriter.consumer.addThread(this);

原來還是從docWriter中來的, 我們繼續查看docWriter裡面是怎樣進行的初始化的.

DocumentsWriter(Directory directory, IndexWriter writer, IndexingChain indexingChain) throws IOException {
  //...省略了
  consumer = indexingChain.getChain(this);
  if (consumer instanceof DocFieldProcessor) {
   docFieldProcessor = (DocFieldProcessor) consumer;
  }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.