join: avoid repeat BytesRefHash.sort() in TermsQuery after TermsIncludingScoreQuery

This commit is contained in:
Christine Poerschke 2024-01-16 13:07:03 +00:00
parent 340d9d2f9c
commit 4ec9ed7177
2 changed files with 19 additions and 2 deletions

View File

@ -131,7 +131,7 @@ class TermsIncludingScoreQuery extends Query implements Accountable {
if (scoreMode.needsScores() == false) { if (scoreMode.needsScores() == false) {
// We don't need scores then quickly change the query: // We don't need scores then quickly change the query:
TermsQuery termsQuery = TermsQuery termsQuery =
new TermsQuery(toField, terms, fromField, fromQuery, topReaderContextId); new TermsQuery(toField, terms, ords, fromField, fromQuery, topReaderContextId);
return searcher return searcher
.rewrite(termsQuery) .rewrite(termsQuery)
.createWeight(searcher, org.apache.lucene.search.ScoreMode.COMPLETE_NO_SCORES, boost); .createWeight(searcher, org.apache.lucene.search.ScoreMode.COMPLETE_NO_SCORES, boost);

View File

@ -63,9 +63,26 @@ class TermsQuery extends MultiTermQuery implements Accountable {
String fromField, String fromField,
Query fromQuery, Query fromQuery,
Object indexReaderContextId) { Object indexReaderContextId) {
this(toField, terms, terms.sort(), fromField, fromQuery, indexReaderContextId);
}
/**
* @param toField The field that should contain terms that are specified in the next parameter.
* @param terms The terms that matching documents should have. The terms must be sorted by natural
* order.
* @param indexReaderContextId Refers to the top level index reader used to create the set of
* terms in the previous parameter.
*/
TermsQuery(
String toField,
BytesRefHash terms,
int[] ords,
String fromField,
Query fromQuery,
Object indexReaderContextId) {
super(toField, CONSTANT_SCORE_BLENDED_REWRITE); super(toField, CONSTANT_SCORE_BLENDED_REWRITE);
this.terms = terms; this.terms = terms;
ords = terms.sort(); this.ords = ords;
this.fromField = fromField; this.fromField = fromField;
this.fromQuery = fromQuery; this.fromQuery = fromQuery;
this.indexReaderContextId = indexReaderContextId; this.indexReaderContextId = indexReaderContextId;