Skip to content

Skip two phase rescore for sort query - #1898

Merged
heemin32 merged 2 commits into
opensearch-project:mainfrom
chishui:two-phase-fix
Jul 8, 2026
Merged

Skip two phase rescore for sort query#1898
heemin32 merged 2 commits into
opensearch-project:mainfrom
chishui:two-phase-fix

Conversation

@chishui

@chishui chishui commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

skip two_phase optimization for query containing sort field.

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

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.

Signed-off-by: Liyun Xiu <xiliyun@amazon.com>
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit 4ccba1b)

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

Latest suggestions up to 4ccba1b
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Guard against null search source builder

processRequest dereferences request.source() without a null check when calling
hasIncompatibleSort, and this method dereferences searchSourceBuilder.sorts()
directly. If the source is ever null (or to be defensive), a NullPointerException
would occur. Guard against a null searchSourceBuilder to make the helper safe and
consistent with typical defensive usage.

src/main/java/org/opensearch/neuralsearch/processor/NeuralSparseTwoPhaseProcessor.java [163-173]

 static boolean hasIncompatibleSort(final SearchSourceBuilder searchSourceBuilder) {
+    if (searchSourceBuilder == null) {
+        return false;
+    }
     List<SortBuilder<?>> sorts = searchSourceBuilder.sorts();
     if (sorts == null || sorts.isEmpty()) {
         return false;
     }
     if (sorts.size() == 1) {
         SortBuilder<?> only = sorts.get(0);
         return !(only instanceof ScoreSortBuilder) || only.order() != SortOrder.DESC;
     }
     return true;
 }
Suggestion importance[1-10]: 3

__

Why: The existing code in processRequest already dereferences request.source().query() right after calling hasIncompatibleSort, so a null source would fail there anyway. The defensive null check is a minor improvement with limited impact.

Low

Previous suggestions

Suggestions up to commit c086709
CategorySuggestion                                                                                                                                    Impact
Possible issue
Guard against null search source

request.source() can be null (e.g., when no search body is provided), which would
cause a NullPointerException when passed to hasIncompatibleSort. Guard against a
null source before invoking the check, or handle null inside hasIncompatibleSort.

src/main/java/org/opensearch/neuralsearch/processor/NeuralSparseTwoPhaseProcessor.java [114-116]

-if (hasIncompatibleSort(request.source())) {
+if (request.source() != null && hasIncompatibleSort(request.source())) {
     return request;
 }
Suggestion importance[1-10]: 3

__

Why: The code immediately below (request.source().query()) already dereferences request.source() without a null check, so if a null source were possible it would fail there too. This suggests the code path assumes source is non-null, making the suggestion of limited impact.

Low

Signed-off-by: Liyun Xiu <xiliyun@amazon.com>
@chishui chishui changed the title skip two phase rescore for sort query Skip two phase rescore for sort query Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit 4ccba1b

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.42%. Comparing base (a5e4e8f) to head (4ccba1b).

Files with missing lines Patch % Lines
...earch/processor/NeuralSparseTwoPhaseProcessor.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1898      +/-   ##
============================================
- Coverage     83.46%   83.42%   -0.04%     
- Complexity     3893     3896       +3     
============================================
  Files           291      291              
  Lines         13835    13844       +9     
  Branches       2300     2304       +4     
============================================
+ Hits          11547    11550       +3     
- Misses         1455     1458       +3     
- Partials        833      836       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@heemin32
heemin32 merged commit 89afaf1 into opensearch-project:main Jul 8, 2026
34 of 49 checks passed
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