3

I am using Lucene 8.10.1. I have the following code :

IndexReader reader = DirectoryReader.open(FSDirectory.open(Paths.get(index)));
try
{
      Fields fields = MultiFields.getFields(reader);
      for (String termfield : fields) {
        Terms terms = fields.terms(termfield);
        TermsEnum termsEnum = terms.iterator(null);
        int count = 0;
        while (termsEnum.next() != null) {
          count++;
        }
        System.out.println(count);
      }
    }

But I am running into this error.

java: cannot find symbol
  symbol:   method getFields(org.apache.lucene.index.IndexReader)
  location: class org.apache.lucene.index.MultiFields

Couldn't find anything in the docs of 8.10.1. Please help! Thank you!

Kiera.K
  • 317
  • 1
  • 13
  • 3
    `MultiFields.getFields()` has been removed as of Lucene version 8.0 ([LUCENE-8513](https://issues.apache.org/jira/browse/LUCENE-8513)). I guess you will have to use `FieldInfos.getIndexedFields(reader)` or `FieldInfos.getMergedFieldInfos(reader)`, and then for each field `MultiTerms.getTerms(reader, field)`. I leave it as a comment as I can't test right now, let us know if it works. – EricLavault Nov 04 '21 at 13:51
  • 1
    I think MultiTerms.getTerms(reader, field) will suffice. – Mohammad Taghipour Nov 07 '21 at 12:53
  • `MultiTerms.getTerms(reader, field)` worked for me in Lucene 8.11.0. – Doi Jun 15 '22 at 14:10

0 Answers0