|
7 | 7 | import static org.apache.lucene.search.DocIdSetIterator.NO_MORE_DOCS;
|
8 | 8 | import static org.mockito.ArgumentMatchers.anyInt;
|
9 | 9 | import static org.mockito.Mockito.mock;
|
10 |
| -import static org.mockito.Mockito.never; |
11 |
| -import static org.mockito.Mockito.times; |
12 | 10 | import static org.mockito.Mockito.verify;
|
13 | 11 | import static org.mockito.Mockito.when;
|
14 | 12 | import static org.opensearch.neuralsearch.util.TestUtils.DELTA_FOR_SCORE_ASSERTION;
|
|
21 | 19 | import java.util.List;
|
22 | 20 | import java.util.Set;
|
23 | 21 | import java.util.concurrent.atomic.AtomicInteger;
|
24 |
| -import java.util.stream.Collectors; |
25 | 22 |
|
26 | 23 | import org.apache.commons.lang3.tuple.ImmutablePair;
|
27 | 24 | import org.apache.commons.lang3.tuple.Pair;
|
@@ -58,113 +55,6 @@ public void testWithRandomDocuments_whenOneSubScorer_thenReturnSuccessfully() {
|
58 | 55 | testWithQuery(docs, scores, hybridQueryScorer);
|
59 | 56 | }
|
60 | 57 |
|
61 |
| - @SneakyThrows |
62 |
| - public void testWithRandomDocumentsAndHybridScores_whenMultipleScorers_thenReturnSuccessfully() { |
63 |
| - int maxDocId1 = TestUtil.nextInt(random(), 10, 10_000); |
64 |
| - Pair<int[], float[]> docsAndScores1 = generateDocuments(maxDocId1); |
65 |
| - int[] docs1 = docsAndScores1.getLeft(); |
66 |
| - float[] scores1 = docsAndScores1.getRight(); |
67 |
| - int maxDocId2 = TestUtil.nextInt(random(), 10, 10_000); |
68 |
| - Pair<int[], float[]> docsAndScores2 = generateDocuments(maxDocId2); |
69 |
| - int[] docs2 = docsAndScores2.getLeft(); |
70 |
| - float[] scores2 = docsAndScores2.getRight(); |
71 |
| - |
72 |
| - Weight weight = mock(Weight.class); |
73 |
| - |
74 |
| - HybridQueryScorer hybridQueryScorer = new HybridQueryScorer( |
75 |
| - Arrays.asList( |
76 |
| - scorer(docs1, scores1, fakeWeight(new MatchAllDocsQuery())), |
77 |
| - scorer(docs2, scores2, fakeWeight(new MatchNoDocsQuery())) |
78 |
| - ) |
79 |
| - ); |
80 |
| - int doc = -1; |
81 |
| - int numOfActualDocs = 0; |
82 |
| - Set<Integer> uniqueDocs1 = Arrays.stream(docs1).boxed().collect(Collectors.toSet()); |
83 |
| - Set<Integer> uniqueDocs2 = Arrays.stream(docs2).boxed().collect(Collectors.toSet()); |
84 |
| - while (doc != NO_MORE_DOCS) { |
85 |
| - doc = hybridQueryScorer.iterator().nextDoc(); |
86 |
| - if (doc == DocIdSetIterator.NO_MORE_DOCS) { |
87 |
| - continue; |
88 |
| - } |
89 |
| - float[] actualTotalScores = hybridQueryScorer.hybridScores(); |
90 |
| - float actualTotalScore = 0.0f; |
91 |
| - for (float score : actualTotalScores) { |
92 |
| - actualTotalScore += score; |
93 |
| - } |
94 |
| - float expectedScore = 0.0f; |
95 |
| - if (uniqueDocs1.contains(doc)) { |
96 |
| - int idx = Arrays.binarySearch(docs1, doc); |
97 |
| - expectedScore += scores1[idx]; |
98 |
| - } |
99 |
| - if (uniqueDocs2.contains(doc)) { |
100 |
| - int idx = Arrays.binarySearch(docs2, doc); |
101 |
| - expectedScore += scores2[idx]; |
102 |
| - } |
103 |
| - assertEquals(expectedScore, actualTotalScore, DELTA_FOR_SCORE_ASSERTION); |
104 |
| - numOfActualDocs++; |
105 |
| - } |
106 |
| - |
107 |
| - int totalUniqueCount = uniqueDocs1.size(); |
108 |
| - for (int n : uniqueDocs2) { |
109 |
| - if (!uniqueDocs1.contains(n)) { |
110 |
| - totalUniqueCount++; |
111 |
| - } |
112 |
| - } |
113 |
| - assertEquals(totalUniqueCount, numOfActualDocs); |
114 |
| - } |
115 |
| - |
116 |
| - @SneakyThrows |
117 |
| - public void testWithRandomDocumentsAndCombinedScore_whenMultipleScorers_thenReturnSuccessfully() { |
118 |
| - int maxDocId1 = TestUtil.nextInt(random(), 10, 10_000); |
119 |
| - Pair<int[], float[]> docsAndScores1 = generateDocuments(maxDocId1); |
120 |
| - int[] docs1 = docsAndScores1.getLeft(); |
121 |
| - float[] scores1 = docsAndScores1.getRight(); |
122 |
| - int maxDocId2 = TestUtil.nextInt(random(), 10, 10_000); |
123 |
| - Pair<int[], float[]> docsAndScores2 = generateDocuments(maxDocId2); |
124 |
| - int[] docs2 = docsAndScores2.getLeft(); |
125 |
| - float[] scores2 = docsAndScores2.getRight(); |
126 |
| - |
127 |
| - HybridQueryScorer hybridQueryScorer = new HybridQueryScorer( |
128 |
| - Arrays.asList( |
129 |
| - scorer(docs1, scores1, fakeWeight(new MatchAllDocsQuery())), |
130 |
| - scorer(docs2, scores2, fakeWeight(new MatchNoDocsQuery())) |
131 |
| - ) |
132 |
| - ); |
133 |
| - int doc = -1; |
134 |
| - int numOfActualDocs = 0; |
135 |
| - Set<Integer> uniqueDocs1 = Arrays.stream(docs1).boxed().collect(Collectors.toSet()); |
136 |
| - Set<Integer> uniqueDocs2 = Arrays.stream(docs2).boxed().collect(Collectors.toSet()); |
137 |
| - while (doc != NO_MORE_DOCS) { |
138 |
| - doc = hybridQueryScorer.iterator().nextDoc(); |
139 |
| - if (doc == DocIdSetIterator.NO_MORE_DOCS) { |
140 |
| - continue; |
141 |
| - } |
142 |
| - float expectedScore = 0.0f; |
143 |
| - if (uniqueDocs1.contains(doc)) { |
144 |
| - int idx = Arrays.binarySearch(docs1, doc); |
145 |
| - expectedScore += scores1[idx]; |
146 |
| - } |
147 |
| - if (uniqueDocs2.contains(doc)) { |
148 |
| - int idx = Arrays.binarySearch(docs2, doc); |
149 |
| - expectedScore += scores2[idx]; |
150 |
| - } |
151 |
| - float hybridScore = 0.0f; |
152 |
| - for (float score : hybridQueryScorer.hybridScores()) { |
153 |
| - hybridScore += score; |
154 |
| - } |
155 |
| - assertEquals(expectedScore, hybridScore, DELTA_FOR_SCORE_ASSERTION); |
156 |
| - numOfActualDocs++; |
157 |
| - } |
158 |
| - |
159 |
| - int totalUniqueCount = uniqueDocs1.size(); |
160 |
| - for (int n : uniqueDocs2) { |
161 |
| - if (!uniqueDocs1.contains(n)) { |
162 |
| - totalUniqueCount++; |
163 |
| - } |
164 |
| - } |
165 |
| - assertEquals(totalUniqueCount, numOfActualDocs); |
166 |
| - } |
167 |
| - |
168 | 58 | @SneakyThrows
|
169 | 59 | public void testWithRandomDocuments_whenMultipleScorersAndSomeScorersEmpty_thenReturnSuccessfully() {
|
170 | 60 | int maxDocId = TestUtil.nextInt(random(), 10, 10_000);
|
@@ -202,11 +92,6 @@ public void testMaxScore_whenMultipleScorers_thenSuccessful() {
|
202 | 92 |
|
203 | 93 | maxScore = hybridQueryScorerWithSomeNullSubScorers.getMaxScore(Integer.MAX_VALUE);
|
204 | 94 | assertTrue(maxScore > 0.0f);
|
205 |
| - |
206 |
| - HybridQueryScorer hybridQueryScorerWithAllNullSubScorers = new HybridQueryScorer(Arrays.asList(null, null)); |
207 |
| - |
208 |
| - maxScore = hybridQueryScorerWithAllNullSubScorers.getMaxScore(Integer.MAX_VALUE); |
209 |
| - assertEquals(0.0f, maxScore, 0.0f); |
210 | 95 | }
|
211 | 96 |
|
212 | 97 | @SneakyThrows
|
@@ -517,14 +402,6 @@ public void testScore_whenMultipleQueries_thenCombineScores() {
|
517 | 402 | assertEquals("Combined score should be sum of bool and neural scores", 1.6f, combinedScore, DELTA_FOR_SCORE_ASSERTION);
|
518 | 403 | }
|
519 | 404 |
|
520 |
| - @SneakyThrows |
521 |
| - public void testScore_whenEmptySubScorers_thenReturnZero() { |
522 |
| - HybridQueryScorer hybridScorer = new HybridQueryScorer(Collections.emptyList()); |
523 |
| - float score = hybridScorer.score(null); |
524 |
| - |
525 |
| - assertEquals("Score should be 0.0 for null wrapper", 0.0f, score, DELTA_FOR_SCORE_ASSERTION); |
526 |
| - } |
527 |
| - |
528 | 405 | @SneakyThrows
|
529 | 406 | public void testInitialization_whenValidScorer_thenSuccessful() {
|
530 | 407 | // Create scorer with iterator
|
@@ -558,46 +435,6 @@ public void testInitialization_whenValidScorer_thenSuccessful() {
|
558 | 435 | assertEquals("Cost should be 1", 1L, wrapper.cost);
|
559 | 436 | }
|
560 | 437 |
|
561 |
| - @SneakyThrows |
562 |
| - public void testHybridScores_withTwoPhaseIterator() throws IOException { |
563 |
| - // Create weight and scorers |
564 |
| - Scorer scorer1 = mock(Scorer.class); |
565 |
| - TwoPhaseIterator twoPhaseIterator = mock(TwoPhaseIterator.class); |
566 |
| - DocIdSetIterator approximation = mock(DocIdSetIterator.class); |
567 |
| - |
568 |
| - // Setup two-phase behavior |
569 |
| - when(scorer1.twoPhaseIterator()).thenReturn(twoPhaseIterator); |
570 |
| - when(twoPhaseIterator.approximation()).thenReturn(approximation); |
571 |
| - when(scorer1.iterator()).thenReturn(approximation); |
572 |
| - when(approximation.cost()).thenReturn(1L); |
573 |
| - |
574 |
| - // Setup DocIdSetIterator behavior - use different docIDs |
575 |
| - when(approximation.docID()).thenReturn(5); // approximation at doc 5 |
576 |
| - when(scorer1.docID()).thenReturn(5); // scorer at same doc |
577 |
| - when(scorer1.score()).thenReturn(2.0f); |
578 |
| - |
579 |
| - // matches() always returns false - document should never match |
580 |
| - when(twoPhaseIterator.matches()).thenReturn(false); |
581 |
| - |
582 |
| - // Create HybridQueryScorer with two-phase iterator |
583 |
| - List<Scorer> subScorers = Collections.singletonList(scorer1); |
584 |
| - HybridQueryScorer hybridScorer = new HybridQueryScorer(subScorers); |
585 |
| - |
586 |
| - // Call matches() first to establish non-matching state |
587 |
| - TwoPhaseIterator hybridTwoPhase = hybridScorer.twoPhaseIterator(); |
588 |
| - assertNotNull("Should have two phase iterator", hybridTwoPhase); |
589 |
| - assertFalse("Document should not match", hybridTwoPhase.matches()); |
590 |
| - |
591 |
| - // Get scores - should be zero since document doesn't match |
592 |
| - float[] scores = hybridScorer.hybridScores(); |
593 |
| - assertEquals("Should have one score entry", 1, scores.length); |
594 |
| - assertEquals("Score should be 0 for non-matching document", 0.0f, scores[0], DELTA_FOR_SCORE_ASSERTION); |
595 |
| - |
596 |
| - // Verify score() was never called since document didn't match |
597 |
| - verify(scorer1, never()).score(); |
598 |
| - verify(twoPhaseIterator, times(1)).matches(); |
599 |
| - } |
600 |
| - |
601 | 438 | @SneakyThrows
|
602 | 439 | public void testTwoPhaseIterator_withNestedTwoPhaseQuery() {
|
603 | 440 | // Create a scorer that uses two-phase iteration
|
|
0 commit comments