Can any one suggest me the best way to get Hits( no of occurrences ) of a word per document in Lucene?..
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Lucene uses a field-based, rather than document-based, index. In order to get term counts per document:
- Iterate over documents using IndexReader.document() and isDeleted().
- In document d, iterate over fields using Document.getFields().
- For each field f, get terms using getTermFreqVector().
- Go over the term vector and sum frequencies per terms.
- The sum of term frequencies per field will give you the document's term frequency vector.
回答2:
SpanTermQuery.getSpans will give an enumeration of docs and where the terms appears. The docs are sorted, so you can just count the number of times each doc appears, ignoring the position info.