Aravind Chinta
Aravind Chinta

Reputation: 71

Lucene - How to access the documents are a hit in the search?

I am basically making a search engine. I have searched for a query and I have used QueryParser and now I have the no of hits for the query in TopDocs object. Now, how do I access the hit documents that I have got in the search. I want to display the those documents which are a hit. How do I do it! Any kind of help appreciated.

Upvotes: 0

Views: 83

Answers (1)

Marko Topolnik
Marko Topolnik

Reputation: 200138

for (ScoreDoc sd : topDocs.scoreDocs) {
  if (sd.doc == Integer.MAX_VALUE) break;
  final Document d = searcher.doc(sd.doc);
  final Fieldable f = d.getFieldable(name);
  ...
}

Hope this helps as a start. Of course, this will not work if you didn't store the field at index time.

Upvotes: 1

Related Questions