lucene统计关键词匹配次数

IndexSearcher search = new IndexSearcher(dir);
IndexReader reader = search.getIndexReader();
if(reader instanceof SegmentReader){
SegmentReader sreader =(SegmentReader)reader;
//拿到Field的位置
      fieldPosition=sreader.getFieldInfos().fieldNumber("content");
}
//拿到content Field的坐标,频率等信息
TermPositionVector tpv = (TermPositionVector) reader.getTermFreqVector(id, "content");
// int fieldNumber = fieldInfos.fieldNumber(field);
int[] fre=tpv.getTermFrequencies();
//拿到词频
System.out.println(fre[fieldPosition]);

SegmentReader不是PUBLIC..修改下源文件.

 


2.reader.docFreq(new Term("",""))拿到整个索引文件Term中内容的词频

你可能感兴趣的:(Lucene)