How do I retrieve all the values of a particular field that exists within an index, across all documents?
Created May 7, 2012
Otis Gospodnetic The trick is to enumerate terms with that field. Terms are sorted first
by field, then by text, so all terms with a given field are adjacent in
enumerations. Term enumeration is also efficient.
try
{
TermEnum terms = indexReader.terms(new Term("FIELD-NAME-HERE", ""));
while ("FIELD-NAME-HERE".equals(enum.term().field()))
{
// ... collect enum.term().text() ...
if (!terms.next())
break;
}
}
finally
{
terms.close();
}