【问题标题】:Print words in the index - Lucene打印索引中的单词 - Lucene
【发布时间】:2017-02-13 12:05:53
【问题描述】:

我对 Lucene 很陌生,我正在使用 Lucene 4.10.4。为了澄清一下,我正在尝试打印 lucene 在搜索期间从索引中读取的所有单词。我试图根据搜索字符串来了解 Lucene 比较跳过了索引中的所有单词。我尝试在某些 lucene 类中使用打印语句打印单词。但它没有用。我在哪里可以使用打印语句?

【问题讨论】:

    标签: java lucene


    【解决方案1】:

    像这样的东西,应该适合你。此代码打开 Lucene 索引并遍历所有字段并列出所有术语。您可以在这里轻松跳过不需要的字段

            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();
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2011-03-19
      • 1970-01-01
      • 2011-07-13
      • 1970-01-01
      • 1970-01-01
      • 2017-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多