Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased 3.x]
### Added
- Add getWrappedScorer method to ProfileScorer for plugin access to wrapped scorers ([#20548](https://github.com/opensearch-project/OpenSearch/issues/20548))
- Support expected cluster name with validation in CCS Sniff mode ([#20532](https://github.com/opensearch-project/OpenSearch/pull/20532))

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ final class ProfileScorer extends Scorer {
setMinCompetitiveScoreTimer = profile.getTimer(QueryTimingType.SET_MIN_COMPETITIVE_SCORE);
}

/**
* Returns the wrapped scorer.
* <p>
* This is useful for plugin queries that extend the Scorer API with custom methods not part of the standard
* Lucene Scorer interface. For example, neural-search's HybridQuery needs to access its HybridBulkScorer
* to call custom methods when profiling is enabled.
* </p>
* <p>
* <b>Note:</b> Calling mutation methods (like {@link #setMinCompetitiveScore(float)}) directly on the
* wrapped scorer will bypass profiling instrumentation for those calls. For read-only access or accessing
* custom methods not part of the standard Scorer API, this is safe and expected.
* </p>
*
* @return the underlying wrapped scorer
* @see ProfileCollector#getDelegate()
*/
public Scorer getWrappedScorer() {
return scorer;
}

@Override
public int docID() {
return scorer.docID();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,15 @@ public void testPropagateMaxScore() throws IOException {
fakeScorer.maxScore = 42f;
assertEquals(42f, profileScorer.getMaxScore(DocIdSetIterator.NO_MORE_DOCS), 0f);
}

public void testGetWrappedScorer() throws IOException {
Query query = new MatchAllDocsQuery();
Weight weight = query.createWeight(new IndexSearcher(new MultiReader()), ScoreMode.TOP_SCORES, 1f);
FakeScorer fakeScorer = new FakeScorer(weight);
QueryProfileBreakdown profile = new QueryProfileBreakdown(ProfileMetricUtil.getDefaultQueryProfileMetrics());
ProfileScorer profileScorer = new ProfileScorer(fakeScorer, profile);

// Verify getWrappedScorer returns the original scorer
assertSame(fakeScorer, profileScorer.getWrappedScorer());
}
}
Loading