Skip to content

Fix the all-cached early return in DirectoryTaxonomyReader#getBulkOrdinals - #16783

Open
xande wants to merge 3 commits into
apache:mainfrom
xande:fix-getbulkordinals-all-cached
Open

xande wants to merge 3 commits into
apache:mainfrom
xande:fix-getbulkordinals-all-cached

Conversation

@xande

@xande xande commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

I was exploring the code with Claude and found that DirectoryTaxonomyReader#getBulkOrdinals has an early return for the case where every requested label is already in the ordinal cache, but that early return never triggered.

The condition for early return checks indexesMissingFromCache.length == 0, which is the capacity of the miss array (Math.min(10, categoryPaths.length)), not the number of misses. Calls with fewer than two labels return before this point, so the capacity here is always at least 2.

As a result, a fully cached call still sorts an empty array and creates a TermsEnum over all taxonomy segments. The returned ordinals were always correct, it it just an optimization.

@epotyom epotyom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks for the fix!

DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(dir);
taxoReader.getBulkOrdinals(a, b); // fills the ordinal cache
// all ordinals are cached now, so the lookup must not touch the index reader at all
taxoReader.getInternalIndexReader().close();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice trick :-)

Comment thread lucene/CHANGES.txt Outdated
* GITHUB#16667: Rewrite BooleanQuery to MatchNoDocsQuery when it has MUST_NOT clause matching one of
its MUST boost or constant score query clauses. (Egor Potemkin)

* GITHUB#XXXXX: DirectoryTaxonomyReader#getBulkOrdinals now returns early when every requested label

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace with real PR id!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants