遍历lucene索引库的字段名
更多个人技术分享,请访问http://www.derekchou.com
try { Collection<String> fn = null; String[] idxFields = null; IndexReader reader = IndexReader.open(ramDir); System.out.println("索引文档列表……"); fn = reader.getFieldNames(IndexReader.FieldOption.ALL); if (fn.size() == 0) { System.out.println("Empty index."); } TreeSet<String> fields = new TreeSet<String>(fn); idxFields = (String[])fields.toArray(new String[fields.size()]); for (int i = 0; i < idxFields.length; i++) { System.out.println(idxFields[i]); } } catch (Exception e) { e.printStackTrace(); }