@@ -287,95 +287,6 @@ public void sendExecuteRankFeature(
287
287
}
288
288
}
289
289
290
- public void testRankFeaturePhaseNoNeedForFetchingFieldData () {
291
- AtomicBoolean phaseDone = new AtomicBoolean (false );
292
- final ScoreDoc [][] finalResults = new ScoreDoc [1 ][1 ];
293
-
294
- // build the appropriate RankBuilder; using a null rankFeaturePhaseRankShardContext
295
- // and non-field based rankFeaturePhaseRankCoordinatorContext
296
- RankBuilder rankBuilder = rankBuilder (
297
- DEFAULT_RANK_WINDOW_SIZE ,
298
- defaultQueryPhaseRankShardContext (Collections .emptyList (), DEFAULT_RANK_WINDOW_SIZE ),
299
- negatingScoresQueryFeaturePhaseRankCoordinatorContext (DEFAULT_SIZE , DEFAULT_FROM , DEFAULT_RANK_WINDOW_SIZE ),
300
- null ,
301
- null
302
- );
303
- // create a SearchSource to attach to the request
304
- SearchSourceBuilder searchSourceBuilder = searchSourceWithRankBuilder (rankBuilder );
305
-
306
- SearchPhaseController controller = searchPhaseController ();
307
- SearchShardTarget shard1Target = new SearchShardTarget ("node0" , new ShardId ("test" , "na" , 0 ), null );
308
-
309
- MockSearchPhaseContext mockSearchPhaseContext = new MockSearchPhaseContext (1 );
310
- mockSearchPhaseContext .getRequest ().source (searchSourceBuilder );
311
- try (SearchPhaseResults <SearchPhaseResult > results = searchPhaseResults (controller , mockSearchPhaseContext )) {
312
- // generate the QuerySearchResults that the RankFeaturePhase would have received from QueryPhase
313
- // here we have 2 results, with doc ids 1 and 2
314
- final ShardSearchContextId ctx = new ShardSearchContextId (UUIDs .base64UUID (), 123 );
315
- QuerySearchResult queryResult = new QuerySearchResult (ctx , shard1Target , null );
316
-
317
- try {
318
- queryResult .setShardIndex (shard1Target .getShardId ().getId ());
319
- int totalHits = randomIntBetween (2 , 100 );
320
- final ScoreDoc [] shard1Docs = new ScoreDoc [] { new ScoreDoc (1 , 10.0F ), new ScoreDoc (2 , 9.0F ) };
321
- populateQuerySearchResult (queryResult , totalHits , shard1Docs );
322
- results .consumeResult (queryResult , () -> {});
323
- // do not make an actual http request, but rather generate the response
324
- // as if we would have read it from the RankFeatureShardPhase
325
- mockSearchPhaseContext .searchTransport = new SearchTransportService (null , null , null ) {
326
- @ Override
327
- public void sendExecuteRankFeature (
328
- Transport .Connection connection ,
329
- final RankFeatureShardRequest request ,
330
- SearchTask task ,
331
- final ActionListener <RankFeatureResult > listener
332
- ) {
333
- // make sure to match the context id generated above, otherwise we throw
334
- if (request .contextId ().getId () == 123 && Arrays .equals (request .getDocIds (), new int [] { 1 , 2 })) {
335
- listener .onFailure (new UnsupportedOperationException ("should not have reached here" ));
336
- } else {
337
- listener .onFailure (new MockDirectoryWrapper .FakeIOException ());
338
- }
339
- }
340
- };
341
- } finally {
342
- queryResult .decRef ();
343
- }
344
- // override the RankFeaturePhase to skip moving to next phase
345
- RankFeaturePhase rankFeaturePhase = rankFeaturePhase (results , mockSearchPhaseContext , finalResults , phaseDone );
346
- try {
347
- rankFeaturePhase .run ();
348
- mockSearchPhaseContext .assertNoFailure ();
349
- assertTrue (mockSearchPhaseContext .failures .isEmpty ());
350
- assertTrue (phaseDone .get ());
351
-
352
- // in this case there was no additional "RankFeature" results on shards, so we shortcut directly to queryPhaseResults
353
- SearchPhaseResults <SearchPhaseResult > rankPhaseResults = rankFeaturePhase .queryPhaseResults ;
354
- assertNotNull (rankPhaseResults .getAtomicArray ());
355
- assertEquals (1 , rankPhaseResults .getAtomicArray ().length ());
356
- assertEquals (1 , rankPhaseResults .getSuccessfulResults ().count ());
357
-
358
- SearchPhaseResult shardResult = rankPhaseResults .getAtomicArray ().get (0 );
359
- assertTrue (shardResult instanceof QuerySearchResult );
360
- QuerySearchResult rankResult = (QuerySearchResult ) shardResult ;
361
- assertNull (rankResult .rankFeatureResult ());
362
- assertNotNull (rankResult .queryResult ());
363
-
364
- List <ExpectedRankFeatureDoc > expectedFinalResults = List .of (
365
- new ExpectedRankFeatureDoc (2 , 1 , -9.0F , null ),
366
- new ExpectedRankFeatureDoc (1 , 2 , -10.0F , null )
367
- );
368
- assertFinalResults (finalResults [0 ], expectedFinalResults );
369
- } finally {
370
- rankFeaturePhase .rankPhaseResults .close ();
371
- }
372
- } finally {
373
- if (mockSearchPhaseContext .searchResponse .get () != null ) {
374
- mockSearchPhaseContext .searchResponse .get ().decRef ();
375
- }
376
- }
377
- }
378
-
379
290
public void testRankFeaturePhaseOneShardFails () {
380
291
AtomicBoolean phaseDone = new AtomicBoolean (false );
381
292
final ScoreDoc [][] finalResults = new ScoreDoc [1 ][1 ];
@@ -534,7 +445,12 @@ public void sendExecuteRankFeature(
534
445
queryResult .decRef ();
535
446
}
536
447
// override the RankFeaturePhase to raise an exception
537
- RankFeaturePhase rankFeaturePhase = new RankFeaturePhase (results , null , mockSearchPhaseContext , null ) {
448
+ RankFeaturePhase rankFeaturePhase = new RankFeaturePhase (
449
+ results ,
450
+ null ,
451
+ mockSearchPhaseContext ,
452
+ defaultRankFeaturePhaseRankCoordinatorContext (DEFAULT_SIZE , DEFAULT_FROM , DEFAULT_RANK_WINDOW_SIZE )
453
+ ) {
538
454
@ Override
539
455
void innerRun (RankFeaturePhaseRankCoordinatorContext rankFeaturePhaseRankCoordinatorContext ) {
540
456
throw new IllegalArgumentException ("simulated failure" );
@@ -890,36 +806,6 @@ public RankFeatureDoc[] rankAndPaginate(RankFeatureDoc[] rankFeatureDocs) {
890
806
};
891
807
}
892
808
893
- private QueryPhaseRankCoordinatorContext negatingScoresQueryFeaturePhaseRankCoordinatorContext (int size , int from , int rankWindowSize ) {
894
- return new QueryPhaseRankCoordinatorContext (rankWindowSize ) {
895
- @ Override
896
- public ScoreDoc [] rankQueryPhaseResults (
897
- List <QuerySearchResult > rankSearchResults ,
898
- SearchPhaseController .TopDocsStats topDocsStats
899
- ) {
900
- List <ScoreDoc > docScores = new ArrayList <>();
901
- for (QuerySearchResult phaseResults : rankSearchResults ) {
902
- docScores .addAll (Arrays .asList (phaseResults .topDocs ().topDocs .scoreDocs ));
903
- }
904
- ScoreDoc [] sortedDocs = docScores .toArray (new ScoreDoc [0 ]);
905
- // negating scores
906
- Arrays .stream (sortedDocs ).forEach (doc -> doc .score *= -1 );
907
-
908
- Arrays .sort (sortedDocs , Comparator .comparing ((ScoreDoc doc ) -> doc .score ).reversed ());
909
- sortedDocs = Arrays .stream (sortedDocs ).limit (rankWindowSize ).toArray (ScoreDoc []::new );
910
- RankFeatureDoc [] topResults = new RankFeatureDoc [Math .max (0 , Math .min (size , sortedDocs .length - from ))];
911
- // perform pagination
912
- for (int rank = 0 ; rank < topResults .length ; ++rank ) {
913
- ScoreDoc base = sortedDocs [from + rank ];
914
- topResults [rank ] = new RankFeatureDoc (base .doc , base .score , base .shardIndex );
915
- topResults [rank ].rank = from + rank + 1 ;
916
- }
917
- topDocsStats .fetchHits = topResults .length ;
918
- return topResults ;
919
- }
920
- };
921
- }
922
-
923
809
private RankFeaturePhaseRankShardContext defaultRankFeaturePhaseRankShardContext (String field ) {
924
810
return new RankFeaturePhaseRankShardContext (field ) {
925
811
@ Override
@@ -1134,7 +1020,12 @@ private RankFeaturePhase rankFeaturePhase(
1134
1020
AtomicBoolean phaseDone
1135
1021
) {
1136
1022
// override the RankFeaturePhase to skip moving to next phase
1137
- return new RankFeaturePhase (results , null , mockSearchPhaseContext , null ) {
1023
+ return new RankFeaturePhase (
1024
+ results ,
1025
+ null ,
1026
+ mockSearchPhaseContext ,
1027
+ RankFeaturePhase .coordinatorContext (mockSearchPhaseContext .getRequest ().source (), null )
1028
+ ) {
1138
1029
@ Override
1139
1030
public void moveToNextPhase (
1140
1031
SearchPhaseResults <SearchPhaseResult > phaseResults ,
0 commit comments