Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lucene - get document ids from term

Tags:

java

lucene

In Lucene 4.1, I see you can use DirectoryReader.docFreq() to get the number of documents in an index containing a given term. Is there a way to actually get those documents? Either the objects or id numbers would be fine. I think AtomicReader.termDocsEnum() would be useful, but I'm not sure if I can use AtomicReader - I don't see how to create an AtomicReader instance on a given directory.

like image 455
Wisco crew Avatar asked Jan 29 '13 18:01

Wisco crew


1 Answers

Why not just search for it?

IndexSearcher searcher = new IndexSearcher(directoryReader);
TermQuery query = new TermQuery(new Term("field", "term"));
TopDocs topdocs = searcher.query(query, numberToReturn);
like image 52
femtoRgon Avatar answered Oct 20 '22 00:10

femtoRgon