Skip to content

Conversation

@karenyrx
Copy link
Contributor

@karenyrx karenyrx commented Dec 4, 2025

Description

Add support for some missing fields in function-score and highlight related fields in GRPC Search API.

Note: The 2 TODOs in Highlight-related proto utils code will be made once spec fixes in https://github.com/opensearch-project/opensearch-api-specification/pull/1003/files is merged, and a new protobuf version is published.

Related Issues

#19526

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Summary by CodeRabbit

  • New Features

    • Support for additional GRPC search options: field-level highlight settings and multi-value mode for decay scoring.
    • Random score function now accepts 64-bit integer seeds.
  • Tests

    • Added tests validating field-level highlight behavior, decay function multi-value modes, terms lookup defaults, and 64-bit seed handling.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 4, 2025

Walkthrough

Adds protobuf-to-builder mappings for highlight field-level settings, propagates MultiValueMode for decay functions (exp/gauss/linear), accepts int64 seeds for random scoring, and adds corresponding unit tests and a small DecayFunction proto utility class.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Minor changelog bullet edits reflecting new proto field support.
Highlight field-level mappings
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java
Adds field-level handling: order (SCORE), phraseLimit, requireFieldMatch, forceSource, tagsSchema → applies pre/post tags via new private helper applyTagsSchemaToField.
Decay function multi-value mode utility
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java
New package-private utility with parseMultiValueMode converting proto MultiValueMode to OpenSearch MultiValueMode.
Exponential decay function updates
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtils.java
Refactors fromProto to build a unified ExponentialDecayFunctionBuilder and apply MultiValueMode post-parsing; parser helpers now return ExponentialDecayFunctionBuilder.
Gaussian decay function updates
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtils.java
Refactors fromProto to enable MultiValueMode application; parser helpers now return GaussDecayFunctionBuilder.
Linear decay function updates
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtils.java
Refactors fromProto similarly to construct a unified LinearDecayFunctionBuilder and apply MultiValueMode; parser helpers now return LinearDecayFunctionBuilder.
Random score seed handling
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtils.java
Adds handling for int64 seed variant (uses long seed converted via hashing where appropriate).
Highlight unit tests
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java
Adds six tests verifying field-level order, phraseLimit, requireFieldMatch, tagsSchema, forceSource, and full-field mappings.
Terms query lookup tests
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java
Adds test asserting TermsLookup.store defaults to false when omitted.
Decay function multi-value mode tests
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/*DecayFunctionProtoUtilsTests.java
Adds tests (Exp, Gauss, Linear) covering MULTI_VALUE_MODE {MIN, MAX, AVG, UNSPECIFIED} → verifies mapping and default MIN behavior (note: Gauss tests appear duplicated in diff).
Random score tests
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtilsTests.java
Adds testFromProtoWithInt64Seed validating int64 seed handling and conversion.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Attention areas:
    • Verify all call sites accept the more specific builder return types (Exp/Gauss/Linear) after signature changes.
    • Confirm MultiValueMode mapping and defaulting (UNSPECIFIED → MIN) across all decay functions.
    • Review applyTagsSchemaToField for correct pre/post tag application and the TODO about DEFAULT vs STYLED schemas.
    • Inspect duplicated GaussDecayFunctionProtoUtilsTests entries in the diff for accidental duplication.

Possibly related PRs

Suggested labels

enhancement, Search

Suggested reviewers

  • kotwanikunal
  • msfroh
  • sachinpkale
  • shwetathareja
  • andrross

Poem

🐰 I hopped through proto fields so bright,

Mapped decay modes left and right,
Highlights now dress per-field with care,
Long seeds hashed, tests sprinkled in pair,
A tiny rabbit cheers: conversions take flight!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 36.96% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title '[GRPC] Add support for missing proto fields in FunctionScore and Highlight' clearly and concisely describes the main change—adding support for missing proto fields in gRPC function-score and highlight features. The title is specific, directly related to the changeset, and accurately summarizes the primary objective.
Description check ✅ Passed The pull request description follows the template structure with completed Description and Related Issues sections, includes a filled Check List, and provides necessary context about TODOs and dependencies on external spec fixes. All required sections are addressed.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4012437 and 05123eb.

📒 Files selected for processing (1)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: gradle-check
🔇 Additional comments (2)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (2)

1-21: LGTM!

The utility class follows Java best practices: package-private visibility for internal use, a private constructor to prevent instantiation, and clear documentation of its purpose and consumers.


23-38: LGTM! Critical issue resolved.

The method now correctly maps all four supported MultiValueMode values (AVG, MAX, MIN, SUM). The previous critical issue regarding the missing SUM case has been addressed. The implementation properly handles unsupported values with an IllegalArgumentException.


Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 4, 2025

❌ Gradle check result for fd08ef7: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

assertEquals("1", builder.termsLookup().id());
assertEquals("tags", builder.termsLookup().path());
assertEquals("r", builder.termsLookup().routing());
assertTrue("store should be true", builder.termsLookup().store());
Copy link
Contributor Author

@karenyrx karenyrx Dec 5, 2025

Choose a reason for hiding this comment

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

Adding a test here for the field that was added in https://github.com/opensearch-project/OpenSearch/pull/20162/files#diff-6089ea05ecb3ee05e04ecf077a33720e435dcd0fa54075d5d632a84acde02e83
(This change was meant to go into the previous PR but rebase error caused it to be dropped)

@karenyrx karenyrx marked this pull request as ready for review December 5, 2025 07:49
@karenyrx karenyrx requested a review from a team as a code owner December 5, 2025 07:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtilsTests.java (1)

182-257: Solid multi_value_mode coverage; consider DRYing test setup and making default behavior more explicit

The four new tests nicely exercise fromProto for MULTI_VALUE_MODE_MIN, MAX, AVG, and UNSPECIFIED, and the assertions on both builder type and field name look correct.

Two minor, optional improvements:

  • The setup for NumericDecayPlacement + DecayPlacement + DecayFunction is duplicated across these tests. A small helper (e.g., buildNumericDecayFunction(String field, double origin, double scale, MultiValueMode mode)) would make the tests shorter and easier to extend if new modes are added later.
  • The UNSPECIFIED test encodes the assumption that the builder’s default MultiValueMode is MIN. Right now ExpDecayFunctionProtoUtils.fromProto relies on that default rather than setting MIN explicitly when the proto mode is UNSPECIFIED. If the underlying ExponentialDecayFunctionBuilder default ever changes, behavior would silently shift. Consider updating fromProto to explicitly set MultiValueMode.MIN for UNSPECIFIED and keep this test asserting that explicit behavior instead of the builder default.
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtilsTests.java (1)

34-47: Good coverage for the new int64 seed path

This test mirrors the existing int32/string cases and correctly verifies both field propagation and the expected Long.hashCode(...)-based seed value, so it should catch regressions in the long-seed handling. If you later expand this area, you might optionally add a boundary/negative int64 seed case, but it’s not required for this change set.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java (1)

449-462: Consider verifying the applied pre/post tags.

The test verifies the field was created but doesn't assert that the styled tags were actually applied. Since applyTagsSchemaToField sets specific pre/post tags, consider verifying them:

         // The tags schema should have been applied - verify the field was created
         HighlightBuilder.Field field = fields.get(0);
         assertEquals("title", field.name());
+
+        // Verify styled tags were applied
+        String[] preTags = field.preTags();
+        assertNotNull(preTags);
+        assertArrayEquals(HighlightBuilder.DEFAULT_STYLED_PRE_TAG, preTags);
+
+        String[] postTags = field.postTags();
+        assertNotNull(postTags);
+        assertArrayEquals(HighlightBuilder.DEFAULT_STYLED_POST_TAGS, postTags);
     }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0449ce8 and 4012437.

📒 Files selected for processing (13)
  • CHANGELOG.md (1 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java (3 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (1 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtils.java (4 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtils.java (4 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtils.java (5 hunks)
  • modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtils.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtilsTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtilsTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtilsTests.java (1 hunks)
  • modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtilsTests.java (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (9)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (1)
  • DecayFunctionProtoUtils (17-38)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (1)
  • DecayFunctionProtoUtils (17-38)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtilsTests.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtils.java (1)
  • LinearDecayFunctionProtoUtils (28-168)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java (1)
  • HighlightBuilderProtoUtils (29-320)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java (2)
server/src/main/java/org/opensearch/indices/TermsLookup.java (1)
  • TermsLookup (60-269)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtils.java (1)
  • TermsQueryBuilderProtoUtils (28-257)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtils.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/DecayFunctionProtoUtils.java (1)
  • DecayFunctionProtoUtils (17-38)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtilsTests.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtils.java (1)
  • ExpDecayFunctionProtoUtils (28-150)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtilsTests.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtils.java (1)
  • RandomScoreFunctionProtoUtils (19-60)
modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtilsTests.java (1)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtils.java (1)
  • GaussDecayFunctionProtoUtils (28-150)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
  • GitHub Check: gradle-check
  • GitHub Check: precommit (21, ubuntu-latest)
  • GitHub Check: precommit (25, ubuntu-24.04-arm)
  • GitHub Check: assemble (25, ubuntu-latest)
  • GitHub Check: assemble (25, ubuntu-24.04-arm)
  • GitHub Check: precommit (25, ubuntu-latest)
  • GitHub Check: precommit (21, ubuntu-24.04-arm)
  • GitHub Check: precommit (25, macos-15-intel)
  • GitHub Check: precommit (21, windows-2025, true)
  • GitHub Check: assemble (21, ubuntu-latest)
  • GitHub Check: assemble (25, windows-latest)
  • GitHub Check: precommit (25, macos-15)
  • GitHub Check: assemble (21, windows-latest)
  • GitHub Check: Analyze (java)
  • GitHub Check: assemble (21, ubuntu-24.04-arm)
  • GitHub Check: precommit (25, windows-latest)
  • GitHub Check: precommit (21, macos-15-intel)
  • GitHub Check: precommit (21, macos-15)
  • GitHub Check: precommit (21, windows-latest)
🔇 Additional comments (14)
modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/RandomScoreFunctionProtoUtils.java (1)

51-52: Int64 seed handling looks correct and consistent

Adding the hasInt64() branch and passing seed.getInt64() into RandomScoreFunctionBuilder.seed(...) cleanly extends existing int32/string support without changing prior behavior. The precedence order (int32 → int64 → string) is reasonable given the oneof semantics of the proto.

CHANGELOG.md (1)

76-77: LGTM!

The changelog entry is correctly formatted and placed in the appropriate "Changed" section, following the existing conventions.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java (3)

155-157: LGTM!

The TODO comment is well-documented and clearly indicates the dependency on external spec fixes and protobuf version upgrade.


258-272: LGTM!

The field-level settings implementation correctly mirrors the top-level handling patterns for order, phraseLimit, and requireFieldMatch. The tagsSchema appropriately uses a helper method since HighlightBuilder.Field doesn't expose a direct tagsSchema() setter like the parent HighlightBuilder does.


309-319: LGTM!

The helper method correctly applies the styled tags schema using OpenSearch's built-in constants. The TODO for HIGHLIGHTER_TAGS_SCHEMA_DEFAULT is appropriately tracked pending the spec fix. The defensive IllegalArgumentException in the default case is a reasonable approach for handling unexpected enum values.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/HighlightBuilderProtoUtilsTests.java (2)

478-536: LGTM!

Comprehensive test covering the combination of all field settings. Good practice to document the package-private fields that can't be verified directly.


407-419: LGTM!

The new field-level tests for order, phraseLimit, requireFieldMatch, and forceSource correctly validate the proto-to-builder mappings and follow the existing test patterns in the file.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/TermsQueryBuilderProtoUtilsTests.java (1)

175-180: LGTM! Enhanced test coverage for lookup property propagation.

The added assertions comprehensively validate that all lookup properties (index, id, path, routing, store) are correctly propagated from the protobuf to the builder.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtilsTests.java (1)

196-271: LGTM! Well-structured tests for MultiValueMode handling.

The four new tests comprehensively cover the MultiValueMode enum values (MIN, MAX, AVG, UNSPECIFIED) and follow consistent patterns with clear assertions. The test structure aligns well with existing tests in the file. The tests are well-written with appropriate setup, execution, and verification phases. If MultiValueMode.MIN is not the actual default for LinearDecayFunctionBuilder, the testFromProtoWithMultiValueModeUnspecified test will catch this at runtime.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/ExpDecayFunctionProtoUtils.java (1)

44-70: LGTM: Multi-value mode integration follows a clean pattern.

The refactored fromProto method correctly:

  1. Uses a concrete ExponentialDecayFunctionBuilder variable to enable post-processing
  2. Applies MultiValueMode only when present and not UNSPECIFIED
  3. Delegates to the shared DecayFunctionProtoUtils.parseMultiValueMode for consistent mapping

The pattern is consistent with sibling implementations (GaussDecayFunctionProtoUtils, LinearDecayFunctionProtoUtils).

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/LinearDecayFunctionProtoUtils.java (1)

44-70: LGTM: Implementation is consistent with sibling decay function utilities.

The multi-value mode handling pattern is correctly applied, matching ExpDecayFunctionProtoUtils and GaussDecayFunctionProtoUtils.

modules/transport-grpc/src/main/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtils.java (1)

44-70: LGTM: Consistent implementation across decay function utilities.

The multi-value mode handling is correctly implemented and consistent with ExpDecayFunctionProtoUtils and LinearDecayFunctionProtoUtils.

modules/transport-grpc/src/test/java/org/opensearch/transport/grpc/proto/request/search/query/functionscore/GaussDecayFunctionProtoUtilsTests.java (2)

195-251: Good test coverage for MIN, MAX, and AVG multi-value modes.

The tests correctly verify that proto MultiValueMode values are properly converted and applied to the GaussDecayFunctionBuilder.


252-270: Verify the default MultiValueMode behavior is intentional and stable.

The test asserts that MULTI_VALUE_MODE_UNSPECIFIED defaults to MultiValueMode.MIN (line 269). This assumption relies on implicit behavior in GaussDecayFunctionBuilder. Add a comment explaining where this default originates (e.g., "Defaults to MIN per DecayFunction specification" or reference the relevant builder/proto documentation), or extract the expected default to a constant to make the assumption explicit and prevent unexpected breakage if the default changes.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

❌ Gradle check result for 05123eb: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

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.

2 participants