Skip to content

GITHUB#16997 Negative Query Optimizations for Lucene Monitor Presearcher (Part II) - #17032

Merged
romseygeek merged 32 commits into
apache:mainfrom
kotman12:monitor-negative-disjuncts-presearchers
Nov 23, 2026
Merged

romseygeek merged 32 commits into
apache:mainfrom
kotman12:monitor-negative-disjuncts-presearchers

Conversation

@kotman12

@kotman12 kotman12 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

Follow up of #16998

I've kept the core QueryTree changes in the original PR and moved the integration bits into this one. Once the first one merges this diff will get smaller. I may have to port some of the comments from the previous one here.

…dNameMapper (DEFAULT, or pass(i) for multipass).
…notslot

# Conflicts:
#	lucene/CHANGES.txt
queries[i] = new BooleanQuery.Builder();
}
}
Map<String, List<BytesRef>> negatableTerms = new HashMap<>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's a List instead of a BytesRefHash (as in the case of terms) because we don't need to deduplicate.

}
String field = fields.map(entry.getKey());
addField(doc, field, entry.getValue());
if (!field.equals(entry.getKey())) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was moved from MPTFPS so you can argue it is leaking some pass-related behavior into TFPS. However, behaviorally this only matters if you have non-identity field mapper.

*/
private static void addRawTerms(Document doc, String field, BytesRefHash terms) {
BytesRef scratch = new BytesRef();
for (int i = 0; i < terms.size(); i++) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Potentially continuing conversation from #16998 (comment) @romseygeek

// read directly: TermsEnumTokenStream can merge invalid UTF-8 terms, which must not exclude
String notField = field + NOT_SUFFIX;
for (BytesRef term = terms.next(); term != null; term = terms.next()) {
if (terms.docFreq() == maxDoc && termAcceptor.test(notField, term)) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Multi-doc batches don't work well with this feature as currently implemented. I am not a user of the batch feature but analyzing this PR made me realize that they don't work well with the current MultiPassTermFilteredPresearcher either. More details here #17004. I think if we can address the linked issue this won't really be a problem.

@romseygeek romseygeek 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.

This all makes sense to me. Thanks for all your work here @kotman12!

@romseygeek
romseygeek merged commit 894d24e into apache:main Nov 23, 2026
13 checks passed
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