kotman12 commented on code in PR #16998:
URL: https://github.com/apache/lucene/pull/16998#discussion_r4499150331
##########
lucene/monitor/src/java/org/apache/lucene/monitor/TermFilteredPresearcher.java:
##########
@@ -151,6 +180,42 @@ protected boolean accept() {
}
}
+ /** Adds the terms of a field that the term filter accepts, to select
queries */
+ private static void addTerms(
+ DocumentQueryBuilder queryBuilder,
+ String field,
+ TokenStream ts,
+ BiPredicate<String, BytesRef> termAcceptor)
+ throws IOException {
+ TermToBytesRefAttribute termAtt =
ts.addAttribute(TermToBytesRefAttribute.class);
+ while (ts.incrementToken()) {
+ BytesRef term = termAtt.getBytesRef();
+ if (termAcceptor.test(field, term)) {
+ queryBuilder.addTerm(field, BytesRef.deepCopyOf(term));
+ }
+ }
+ ts.close();
+ }
+
+ /**
+ * Adds the terms every document contains, which can exclude queries through
a negative disjunct
+ */
+ private static void addNegatableTerms(
+ DocumentQueryBuilder queryBuilder,
+ String field,
+ TermsEnum terms,
+ int maxDoc,
+ BiPredicate<String, BytesRef> termAcceptor)
+ throws IOException {
+ // 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)) {
Review Comment:
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
https://github.com/apache/lucene/issues/17004. I think if we can address the
linked issue this won't really be a problem.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]