If you are using Lucene 4.0 api, you need to get the fields from the indexer. Fields then offers a way to get conditions for each field in the index. Here is an example of how to do this:
Fields fields = MultiFields.getFields(indexReader); Terms terms = fields.terms("field"); TermsEnum iterator = terms.iterator(null); BytesRef byteRef = null; while((byteRef = iterator.next()) != null) { String term = new String(byteRef.bytes, byteRef.offset, byteRef.length); }
In the end, for the new version of Lucene, you can get the string from the BytesRef call:
byteRef.utf8ToString();
instead
new String(byteRef.bytes, byteRef.offset, byteRef.length);
If you want to get the frequency of the document, you can do:
int docFreq = iterator.docFreq();
pokeRex110
source share