0
我對Lucene非常陌生,我使用的是Lucene 4.10.4。對於一些澄清,我試圖打印所有lucene在搜索期間從索引讀取的單詞。我試圖理解,根據搜索字符串索引中的所有單詞都被從Lucene的比較中跳過。我嘗試在一些lucene類中使用print語句打印單詞。但它沒有奏效。我可以在哪裏使用打印聲明?在索引中打印單詞 - Lucene
我對Lucene非常陌生,我使用的是Lucene 4.10.4。對於一些澄清,我試圖打印所有lucene在搜索期間從索引讀取的單詞。我試圖理解,根據搜索字符串索引中的所有單詞都被從Lucene的比較中跳過。我嘗試在一些lucene類中使用print語句打印單詞。但它沒有奏效。我可以在哪裏使用打印聲明?在索引中打印單詞 - Lucene
像這樣的東西,應該爲你工作。此代碼打開Lucene索引並遍歷所有字段並列出所有術語。你可以在這裏輕鬆地跳過不需要的字段
IndexReader reader = DirectoryReader.open(dir);
final Fields fields = MultiFields.getFields(reader);
final Iterator<String> iterator = fields.iterator();
while(iterator.hasNext()) {
final String field = iterator.next();
final Terms terms = MultiFields.getTerms(reader, field);
final TermsEnum it = terms.iterator(null);
BytesRef term = it.next();
while (term != null) {
System.out.println(term.utf8ToString());
term = it.next();
}
}