Skip to content
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

[Backport 2.x] Minor code fixes to remove code inconsistencies. #2322

Merged
merged 1 commit into from
Dec 11, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ private Weight getFilterWeight(IndexSearcher searcher) throws IOException {

@Override
public void visit(QueryVisitor visitor) {

visitor.visitLeaf(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class NativeEngineKnnVectorQuery extends Query {
@Override
public Weight createWeight(IndexSearcher indexSearcher, ScoreMode scoreMode, float boost) throws IOException {
final IndexReader reader = indexSearcher.getIndexReader();
final KNNWeight knnWeight = (KNNWeight) knnQuery.createWeight(indexSearcher, ScoreMode.COMPLETE, 1);
final KNNWeight knnWeight = (KNNWeight) knnQuery.createWeight(indexSearcher, scoreMode, 1);
List<LeafReaderContext> leafReaderContexts = reader.leaves();
List<Map<Integer, Float>> perLeafResults;
RescoreContext rescoreContext = knnQuery.getRescoreContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class NativeEngineKNNVectorQueryTests extends OpenSearchTestCase {
@InjectMocks
private NativeEngineKnnVectorQuery objectUnderTest;

private static ScoreMode scoreMode = ScoreMode.TOP_SCORES;

@Override
public void setUp() throws Exception {
super.setUp();
Expand All @@ -85,7 +87,7 @@ public void setUp() throws Exception {
when(leaf2.reader()).thenReturn(leafReader2);

when(searcher.getIndexReader()).thenReturn(reader);
when(knnQuery.createWeight(searcher, ScoreMode.COMPLETE, 1)).thenReturn(knnWeight);
when(knnQuery.createWeight(searcher, scoreMode, 1)).thenReturn(knnWeight);

when(searcher.getTaskExecutor()).thenReturn(taskExecutor);
when(taskExecutor.invokeAll(any())).thenAnswer(invocationOnMock -> {
Expand Down Expand Up @@ -135,7 +137,7 @@ public void testMultiLeaf() {
Query expected = new DocAndScoreQuery(4, expectedDocs, expectedScores, findSegments, 1);

// When
Weight actual = objectUnderTest.createWeight(searcher, ScoreMode.COMPLETE, 1);
Weight actual = objectUnderTest.createWeight(searcher, scoreMode, 1);

// Then
assertEquals(expected, actual.getQuery());
Expand Down Expand Up @@ -176,7 +178,7 @@ public void testRescoreWhenShardLevelRescoringEnabled() {
mockedResultUtil.when(() -> ResultUtil.reduceToTopK(any(), anyInt())).thenCallRealMethod();

// When
Weight actual = objectUnderTest.createWeight(searcher, ScoreMode.COMPLETE, 1);
Weight actual = objectUnderTest.createWeight(searcher, scoreMode, 1);

// Then
mockedResultUtil.verify(() -> ResultUtil.reduceToTopK(any(), anyInt()), times(2));
Expand All @@ -199,7 +201,7 @@ public void testSingleLeaf() {
Query expected = new DocAndScoreQuery(4, expectedDocs, expectedScores, findSegments, 1);

// When
Weight actual = objectUnderTest.createWeight(searcher, ScoreMode.COMPLETE, 1);
Weight actual = objectUnderTest.createWeight(searcher, scoreMode, 1);

// Then
assertEquals(expected, actual.getQuery());
Expand All @@ -214,7 +216,7 @@ public void testNoMatch() {
when(knnQuery.getK()).thenReturn(4);

// When
Weight actual = objectUnderTest.createWeight(searcher, ScoreMode.COMPLETE, 1);
Weight actual = objectUnderTest.createWeight(searcher, scoreMode, 1);

// Then
assertEquals(new MatchNoDocsQuery(), actual.getQuery());
Expand Down Expand Up @@ -263,7 +265,7 @@ public void testRescore() {
try (MockedStatic<NativeEngineKnnVectorQuery> mockedStaticNativeKnnVectorQuery = mockStatic(NativeEngineKnnVectorQuery.class)) {
mockedStaticNativeKnnVectorQuery.when(() -> NativeEngineKnnVectorQuery.findSegmentStarts(any(), any()))
.thenReturn(new int[] { 0, 4, 2 });
Weight actual = objectUnderTest.createWeight(searcher, ScoreMode.COMPLETE, 1);
Weight actual = objectUnderTest.createWeight(searcher, scoreMode, 1);
assertEquals(expected, actual.getQuery());
}
}
Expand Down
Loading