简体   繁体   中英

Print words in the index - Lucene

I'm very new to Lucene and I'm using Lucene 4.10.4. For some clarifications, I'm trying to print all the words which lucene read from the index during search time. I'm trying to understand, based on the search string what all the words in the index are skipped from comparing by Lucene. I tried printing the words using print statements in some lucene class. But it didn't work. Where can I use the print statement?

Something like this, should work for you. This code, opens Lucene index and iterating through all fields and lists all terms. You could easily skip not needed fields here

        IndexReader reader = DirectoryReader.open(dir);
        final Fields fields = MultiFields.getFields(reader);
        final Iterator<String> iterator = fields.iterator();

        while(iterator.hasNext()) {
            final String field = iterator.next();
            final Terms terms = MultiFields.getTerms(reader, field);
            final TermsEnum it = terms.iterator(null);
            BytesRef term = it.next();
            while (term != null) {
                System.out.println(term.utf8ToString());
                term = it.next();
            }
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM