1
A
回答
-1
第一件事是獲取文件的列表。替代方案可能會迭代索引術語,但方法IndexReader.terms()
似乎已從4.0中刪除(儘管它存在於AtomicReader
中,值得一看)。我所知道的獲得所有文檔的最佳方法是簡單地循環通過文檔ID的文件:
//where reader is your IndexReader, however you go about opening/managing it
for (int i=0; i<reader.maxDoc(); i++) {
if (reader.isDeleted(i))
continue;
//operate on the document with id = i ...
}
然後,你需要的所有索引項的列表。我假設我們對存儲字段沒有興趣,因爲你想要的數據對他們來說沒有意義。爲了檢索條款,您可以使用IndexReader.getTermVectors(int)
。請注意,我實際上並未檢索文檔,因爲我們不需要直接訪問它。從我們離開的地方繼續:
String field;
FieldsEnum fieldsiterator;
TermsEnum termsiterator;
//To Simplify, you can rely on DefaultSimilarity to calculate tf and idf for you.
DefaultSimilarity freqcalculator = new DefaultSimilarity()
//numDocs and maxDoc are not the same thing:
int numDocs = reader.numDocs();
int maxDoc = reader.maxDoc();
for (int i=0; i<maxDoc; i++) {
if (reader.isDeleted(i))
continue;
fieldsiterator = reader.getTermVectors(i).iterator();
while (field = fieldsiterator.next()) {
termsiterator = fieldsiterator.terms().iterator();
while (terms.next()) {
//id = document id, field = field name
//String representations of the current term
String termtext = termsiterator.term().utf8ToString();
//Get idf, using docfreq from the reader.
//I haven't tested this, and I'm not quite 100% sure of the context of this method.
//If it doesn't work, idfalternate below should.
int idf = termsiterator.docfreq();
int idfalternate = freqcalculator.idf(reader.docFreq(field, termsiterator.term()), numDocs);
}
}
}
相關問題
- 1. 讓Lucene 4.0讀取2.9版本索引
- 2. 如何讀取Lucene索引?
- 3. 閱讀Lucene索引無服務器
- 4. 我想閱讀我的索引與Lucene的單個術語
- 5. 在索引中打印單詞 - Lucene
- 6. Python閱讀txt和打印
- 7. 如何從Solr中讀取Lucene索引
- 8. 重新打開Lucene索引
- 9. TLP 2824桌面打印機如何閱讀打印機狀態
- 10. 閱讀更改和打印PPM圖像
- 11. Python閱讀和打印文本文件
- 12. 閱讀和打印一個隨機數
- 13. 閱讀文件和打印字典
- 14. Python - 閱讀和行間打印?
- 15. 閱讀和打印矩陣C
- 16. .txt閱讀器和打印機
- 17. 閱讀ArrayList索引
- 18. 閱讀打印機數據
- 19. Lucene索引和搜索
- 20. Lucene索引和搜索
- 21. Apache lucene 4.3.1 - 索引閱讀器無法觸及最後索引的文檔
- 22. 如何從Lucene 4.0索引中提取單個文檔?
- 23. 如何閱讀Nutch索引的內容?
- 24. 如何閱讀csv避免索引?
- 25. lucene如何索引文件?
- 26. 如何閱讀和打印從XML C#特定屬性
- 27. 如何編寫和閱讀可打印的ascii?
- 28. 如何閱讀和從MySQL在C#中打印出數據
- 29. 我將如何使用Lucene索引客戶索引
- 30. Apache lucene搜索代碼打印null
好像你可能會尋找這樣的事情:http://stackoverflow.com/questions/2311845/is-it-possible-to-iterate-through-documents-存儲功能於lucene的指數 –