The same IR could be a sub-reader in a different context though.
Right, but that's perfectly fine w/ the proposed API.
Ie, any IR is able to be a top reader if you ask it to. So you can
call IR.getTopReaderInfo(), and this will fill in the full tree as
seen by that top reader only. Meaning, the resulting tree is
"private" to that reader. If you go and ask another reader for its
tree, a new tree (private to that reader's "view" (parent/child
relationships)) is computed.
The API is fully general: it allows for readers that are shared by
more than one top reader.
Really (as Yonik said before) this is a question of caching. It's
gonna be the same tree, whether it's stored on IR or IS. Yet, the
tree in no way depends on IS – it's entirely a function of the
relationships b/w IR and its subs. An app should be able to store the
top IR, and pull the tree from it on demand. And init'ing an IS from
an IR should continue to be cheap.
Also, looking towards the future... at some point we will split apart
"composite reader" and "atomic reader". Ie, these really should be
separate classes, but today in Lucene they are one and the same and so
we have "dynamic typing" (you hit exceptions at runtime) instead of
static typing (compilation errors). At some point we have to fix this
and make these two IRs separately classes.
But to say that this API should be moved to IS instead of IR because
of this dynamic/static typing problem is a step in the wrong direction
– ie once we split out these two IR classes we'll want to move the
the getTopReaderInfo API back to the "composite" IR.
BTW we will have to somehow fix CachingWrapperFilter to behave
properly here. Ie, it needs to know whether the cache key is purely
the sub-reader (as it is, always, today), or the combo of root reader
+ sub (as it is for eg DuplicateFilter).