Wisco crew
Wisco crew

Reputation: 1367

Lucene - get document ids from term

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.

Upvotes: 6

Views: 4784

Answers (1)

femtoRgon
femtoRgon

Reputation: 33341

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);

Upvotes: 6

Related Questions