-
Notifications
You must be signed in to change notification settings - Fork 243
Support named query scores in Hit.matchedQueries() #2098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
reta
merged 5 commits into
opensearch-project:main
from
lawofcycles:matched-queries-score
Aug 13, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3015d5a
Support named query scores in Hit.matchedQueries()
lawofcycles 3e00e3d
Merge remote-tracking branch 'origin/main' into matched-queries-score
lawofcycles b0e8db2
Apply spotless formatting to Overrides.java
lawofcycles 7c5a8cb
Merge remote-tracking branch 'origin/main' into matched-queries-score
lawofcycles c8d0b3b
Rework matched_queries as a MatchedQueries tagged union" -m "Replace the
lawofcycles File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...client/src/test/java/org/opensearch/client/opensearch/core/search/MatchedQueriesTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.client.opensearch.core.search; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.assertTrue; | ||
| import static org.opensearch.client.opensearch.model.ModelTestCase.toJson; | ||
|
|
||
| import jakarta.json.stream.JsonParser; | ||
| import java.io.StringReader; | ||
| import java.util.Map; | ||
| import org.junit.Test; | ||
| import org.opensearch.client.json.JsonData; | ||
| import org.opensearch.client.json.JsonpDeserializer; | ||
| import org.opensearch.client.json.JsonpMapper; | ||
| import org.opensearch.client.json.jsonb.JsonbJsonpMapper; | ||
|
|
||
| public class MatchedQueriesTest { | ||
| private final JsonpMapper mapper = new JsonbJsonpMapper(); | ||
| private final JsonpDeserializer<Hit<JsonData>> hitDeserializer = Hit.createHitDeserializer(JsonData._DESERIALIZER); | ||
|
|
||
| private Hit<JsonData> parse(String json) { | ||
| JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json)); | ||
| return hitDeserializer.deserialize(parser, mapper); | ||
| } | ||
|
|
||
| @Test | ||
| public void deserializesArrayFormAsMapWithNullValues() { | ||
| Hit<JsonData> hit = parse("{\"_index\":\"i\",\"matched_queries\":[\"a\",\"b\"]}"); | ||
| Map<String, Double> matchedQueries = hit.matchedQueries(); | ||
| assertEquals(2, matchedQueries.size()); | ||
| assertTrue(matchedQueries.containsKey("a")); | ||
| assertNull(matchedQueries.get("a")); | ||
| assertNull(matchedQueries.get("b")); | ||
| } | ||
|
|
||
| @Test | ||
| public void deserializesObjectFormAsMapWithScores() { | ||
| Hit<JsonData> hit = parse("{\"_index\":\"i\",\"matched_queries\":{\"a\":1.5,\"b\":2.5}}"); | ||
| Map<String, Double> matchedQueries = hit.matchedQueries(); | ||
| assertEquals(2, matchedQueries.size()); | ||
| assertEquals(Double.valueOf(1.5), matchedQueries.get("a")); | ||
| assertEquals(Double.valueOf(2.5), matchedQueries.get("b")); | ||
| } | ||
|
|
||
| @Test | ||
| public void returnsEmptyMapWhenAbsent() { | ||
| Hit<JsonData> hit = parse("{\"_index\":\"i\"}"); | ||
| assertTrue(hit.matchedQueries().isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| public void serializesAsArrayWhenValuesAreNull() { | ||
| Hit<JsonData> hit = parse("{\"_index\":\"i\",\"matched_queries\":[\"a\",\"b\"]}"); | ||
| assertTrue(toJson(hit, mapper).contains("\"matched_queries\":[\"a\",\"b\"]")); | ||
| } | ||
|
|
||
| @Test | ||
| public void serializesAsObjectWhenScoresPresent() { | ||
| Hit<JsonData> hit = parse("{\"_index\":\"i\",\"matched_queries\":{\"a\":1.5}}"); | ||
| assertTrue(toJson(hit, mapper).contains("\"matched_queries\":{\"a\":1.5}")); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.