简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM