How can I get the number of Hits per document in Lucene in Java. I have
IndexReader reader; reader = IndexReader.open(FSDirectory.open(new File(index)), true); Searcher searcher = new IndexSearcher(reader); String feild = "contents" QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field,analyzer); Query query = parser.parse("test"); TopScoreDocCollector collector = TopScoreDocCollector.create( 5 * hitsPerPage, false); searcher.search(query, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; Searcher searcher = new IndexSearcher(reader); int numTotalHits = collector.getTotalHits(); System.out.println(numTotalHits + " total matching documents");for (int i = start; i < end; i++) { int id = hits[i].doc; TermFreqVector[] Tfv = reader.getTermFreqVectors(id);
The tfv is getting to be null :( Can some one direct on how to get the hits in each document from there.
EDIT:
If we set the TermVector.YES while indexing it works.