I am a very new user of Lucene, and thus far am amazed at its speed and ease of use. I have a question about something in the FAQ though. I have a need to get all terms in a specific section of the document; I want to create a database of term vs an identifier of the document containing the term. There is a part of the FAQ which answers this directly, and says: 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(); } However, this doesn't compile for me; Is "enum" supposed to be "terms"? Also, the terms.close() statement is outside the scope of terms. I changed to the following, is this correct and should the FAQ be changed? try { TermEnum terms = indexReader.terms(new Term("FIELD-NAME-HERE", "")); while ("FIELD-NAME-HERE".equals( terms.term().field())) { // ... collect enum.term().text() ... String term = terms.term().text(); System.out.println(term); if (!terms.next()) break; } terms.close(); } Thanks, and I hope this isn't a crazy question-