Skip to content

LUCENE-6513: Add FrequentTermsSpanBooleanQueryRewrite - #16484

Open
dsmiley wants to merge 1 commit into
apache:mainfrom
dsmiley:LUCENE-6513-Issue7571-SpanFreqTermsRewrite
Open

LUCENE-6513: Add FrequentTermsSpanBooleanQueryRewrite#16484
dsmiley wants to merge 1 commit into
apache:mainfrom
dsmiley:LUCENE-6513-Issue7571-SpanFreqTermsRewrite

Conversation

@dsmiley

@dsmiley dsmiley commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

-- to SpanMultiTermQueryWrapper

See #7571

Adds a SpanRewriteMethod that bounds SpanMultiTermQueryWrapper expansion by retaining only the most frequent terms, ranked by document frequency (DF_ORDER) or document frequency then total term frequency (DF_THEN_TTF_ORDER), or any caller-supplied Comparator. This offers a more meaningful cap than TopTermsSpanBooleanQueryRewrite, whose boost-based ordering degenerates to lexicographical order for most multi-term queries.

It is built on ScoringRewrite rather than TopTermsRewrite because TopTermsRewrite caps terms while collecting them per segment, which requires a ranking key that is stable across segments (such as boost); document and total term frequencies are only per-segment during collection. ScoringRewrite instead collects every matching term first, aggregating TermStates across all segments, after which the maxSize most frequent terms are kept in a PriorityQueue using the aggregated statistics.

Implements equals/hashCode over maxSize and the ordering Comparator for parity with TopTermsSpanBooleanQueryRewrite. Adds TestSpanMultiTermQueryWrapper.testFrequentTermsRewrite covering the frequency-based cap.

…mQueryWrapper

Adds a SpanRewriteMethod that bounds SpanMultiTermQueryWrapper expansion by retaining only the most frequent terms, ranked by document frequency (DF_ORDER) or document frequency then total term frequency (DF_THEN_TTF_ORDER), or any caller-supplied Comparator<ScoreTerm>. This offers a more meaningful cap than TopTermsSpanBooleanQueryRewrite, whose boost-based ordering degenerates to lexicographical order for most multi-term queries.

It is built on ScoringRewrite rather than TopTermsRewrite because TopTermsRewrite caps terms while collecting them per segment, which requires a ranking key that is stable across segments (such as boost); document and total term frequencies are only per-segment during collection. ScoringRewrite instead collects every matching term first, aggregating TermStates across all segments, after which the maxSize most frequent terms are kept in a PriorityQueue using the aggregated statistics.

Implements equals/hashCode over maxSize and the ordering Comparator for parity with TopTermsSpanBooleanQueryRewrite. Adds TestSpanMultiTermQueryWrapper.testFrequentTermsRewrite covering the frequency-based cap.
@dsmiley dsmiley added this to the 10.6.0 milestone Aug 4, 2026
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.

1 participant