kotman12 commented on code in PR #16998:
URL: https://github.com/apache/lucene/pull/16998#discussion_r4497948232
##########
lucene/monitor/src/java/org/apache/lucene/monitor/TermFilteredPresearcher.java:
##########
@@ -254,18 +383,99 @@ public final Document indexQuery(Query query, Map<String,
String> metadata) {
/** Builds a {@link Document} from the terms extracted from a query */
protected Document buildQueryDocument(QueryTree querytree) {
- Map<String, BytesRefHash> fieldTerms = collectTerms(querytree);
+ return toDocument(querytree, field -> field);
+ }
+
+ /** Indexes the terms and negative disjuncts of the current path through a
{@link QueryTree} */
+ Document toDocument(QueryTree querytree, FieldMapper fields) {
Document doc = new Document();
- for (Map.Entry<String, BytesRefHash> entry : fieldTerms.entrySet()) {
- doc.add(
- new Field(
- entry.getKey(),
- new TermsEnumTokenStream(new
BytesRefHashIterator(entry.getValue())),
- QUERYFIELDTYPE));
+ CollectedTerms collected = collectTermsAndNegativeDisjuncts(querytree);
+ List<Set<Term>> negativeDisjuncts = collected.negativeDisjuncts();
+ if (negativeDisjuncts.size() > maxNegativeDisjuncts) {
+ // More negative disjuncts than the document side checks: the marker
alone satisfies the path
+ // for
+ // every document, so its terms are not needed either
+ addField(doc, negativeDisjunctMarkerField(fields, 0),
NEGATIVE_DISJUNCT_MARKER);
+ return doc;
+ }
+ for (Map.Entry<String, BytesRefHash> entry : collected.terms().entrySet())
{
+ if (maxNegativeDisjuncts > 0 && entry.getKey().contains(NOT_SUFFIX)) {
+ // The field could be indexed under the name of a negative disjunct
field, whose clauses
+ // exclude
+ // queries, so select the query for every document instead
+ addField(doc, ANYTOKEN_FIELD, new BytesRef(ANYTOKEN));
+ continue;
+ }
+ String field = fields.map(entry.getKey());
+ addField(doc, field, entry.getValue());
+ if (!field.equals(entry.getKey())) {
+ // the term filter looks terms up under the document's field names, so
a renamed field is
+ // also indexed under its own name
+ addField(doc, entry.getKey(), entry.getValue());
Review Comment:
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.
--
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]