Skip to content

JAVA-6202 - #2023

Open
strogiyotec wants to merge 2 commits into
mongodb:mainfrom
strogiyotec:JAVA-6202
Open

JAVA-6202#2023
strogiyotec wants to merge 2 commits into
mongodb:mainfrom
strogiyotec:JAVA-6202

Conversation

@strogiyotec

@strogiyotec strogiyotec commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

JAVA-6202 Fluent API for $score

The core builder API was written by claude, I just verified that it follows the code practices used in other builders and ran the tests locally

@strogiyotec
strogiyotec requested a review from a team as a code owner July 27, 2026 04:06
@strogiyotec
strogiyotec requested review from apmasell and rozza and removed request for apmasell July 27, 2026 04:06
@rozza
rozza requested a review from Copilot July 27, 2026 11:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds fluent builder support for the aggregation $score stage (MongoDB 8.2+) to driver-core, with corresponding Scala wrapper exposure and rendering/functional test coverage.

Changes:

  • Introduces ScoreOptions, ScoreNormalization, and an internal ScoreConstructibleBson to model $score stage options.
  • Adds Aggregates.score(...) overloads in driver-core and driver-scala.
  • Adds Java functional tests and Scala model rendering specs for $score.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
driver-scala/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala Adds Scala rendering assertions for $score with and without options.
driver-scala/src/main/scala/org/mongodb/scala/model/package.scala Exposes ScoreOptions / ScoreNormalization type aliases in the Scala model package.
driver-scala/src/main/scala/org/mongodb/scala/model/Aggregates.scala Adds Scala Aggregates.score overloads delegating to Java core builders.
driver-core/src/test/functional/com/mongodb/client/model/AggregatesTest.java Adds pipeline rendering tests plus a server-gated functional test verifying computed score behavior.
driver-core/src/main/com/mongodb/client/model/ScoreOptions.java Introduces the public options interface for $score.
driver-core/src/main/com/mongodb/client/model/ScoreNormalization.java Adds the normalization enum and server string mappings.
driver-core/src/main/com/mongodb/client/model/ScoreConstructibleBson.java Implements ScoreOptions using the existing constructible-BSON pattern.
driver-core/src/main/com/mongodb/client/model/Aggregates.java Adds core $score stage builders and BSON encoding logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rozza rozza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its looking good - have a couple of nits.

Comment thread driver-core/src/main/com/mongodb/client/model/ScoreOptions.java
Comment thread driver-scala/src/main/scala/org/mongodb/scala/model/package.scala
}

@Test
public void testScoreWithAllOptions() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request: Adding tests for all normalization types to protect against accidential regressions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added two test cases that inject all enum values

  1. testScoreWithEachNormalization
  2. testScoreOnServerWithEachNormalization

@strogiyotec
strogiyotec requested a review from rozza July 27, 2026 17:04
nhachicha added a commit to nhachicha/mongo-java-driver that referenced this pull request Jul 27, 2026
Temporarily duplicates the ScoreNormalization enum from PR mongodb#2023 so both
branches compile independently; once JAVA-6202 merges, the duplicate is
dropped in favor of theirs.

@rozza rozza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@nhachicha

Copy link
Copy Markdown
Collaborator

Two small doc requests on ScoreNormalization, coming from JAVA-5990 (#2024), which shares this enum for $scoreFusion's input.normalization field (we currently carry a temporary duplicate of this class so both branches compile independently — whichever PR merges second drops its copy, so the wording here becomes the canonical one):

  1. SIGMOID range should be (0, 1), not [0, 1]. sigmoid(x) = 1/(1+e^{-x}) approaches but never reaches 0 or 1 for finite scores, so the interval is open — this PR's own testScore asserts exactly that (scoreValue > 0 && scoreValue < 1). MIN_MAX_SCALER is correctly [0, 1] (the min and max scores map to exactly 0 and 1).

  2. Make the class-level Javadoc stage-neutral. It currently says the enum is "for the $score pipeline stage" and links only to the $score manual page, but the same values serve $scoreFusion's required normalization field (and Copilot already flagged the mismatch on JAVA-5990 Hybrid Search Score Fusion #2024). Suggest e.g. "Normalization methods for the $score and $scoreFusion pipeline stages" — we've applied both tweaks to our duplicate on JAVA-5990 Hybrid Search Score Fusion #2024 so the copies converge on merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants