简体   繁体   English

在索引中打印单词-Lucene

[英]Print words in the index - Lucene

I'm very new to Lucene and I'm using Lucene 4.10.4. 我对Lucene非常陌生,正在使用Lucene 4.10.4。 For some clarifications, I'm trying to print all the words which lucene read from the index during search time. 为了澄清起见,我尝试打印在搜索过程中从索引读取的所有lucene单词。 I'm trying to understand, based on the search string what all the words in the index are skipped from comparing by Lucene. 我试图根据搜索字符串来理解Lucene跳过索引中所有单词的内容。 I tried printing the words using print statements in some lucene class. 我尝试在某些Lucene类中使用print语句来打印单词。 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. 此代码将打开Lucene索引并遍历所有字段并列出所有术语。 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();
            }
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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