It's a little spooky how sneaky this patch needs to be, temporarily
overwriting MergeState members, adding a FilterFieldsProducer,
Can we improve those latter two classes to e.g. reject a field that
was not in the restricted set, if you call
FilterFieldInfos.fieldInfo or FilterFieldsProducer.terms on an
invalid field name?
The FilterFieldsInfos is also in a precarious state, having to include
all incoming FieldInfo instances so the numbers are consistent, yet
only overriding the iterator.
Methods like FilterFieldInfos.hasProx, etc., are also wrong, which can
result in sneaky future bugs for codecs that rely on this.
I don't really like the complexity in this patch: I think this is a little too much
sneakiness. Yet, I don't know of a cleaner way to fix the bug.
Stepping back a bit, can you describe the use case motivating allowing
your custom codec to override the default merging for doc values /