lucene 遍历所有term


        Directory indexDirectory = FSDirectory.open(new File("/home/ranger/index/1"));

        IndexReader indexReader = DirectoryReader.open(indexDirectory);
        Fields fields = MultiFields.getFields(indexReader );
        Iterator<String> fieldsIterator = fields.iterator();
        while(fieldsIterator.hasNext()){
            String field = fieldsIterator.next();
            Terms terms = fields.terms(field);
            TermsEnum termsEnums = terms.iterator(null);
            BytesRef byteRef = null;
            System.out.println("field : "+ field);
            while((byteRef = termsEnums.next()) != null) {
                String term = new String(byteRef.bytes, byteRef.offset, byteRef.length);
                System.out.println("term is : " + term);
            }
        }

结果是:

field : ID
term is : 10000
field : name
term is : lettuce


你可能感兴趣的:(Lucene,term)