File tree Expand file tree Collapse file tree 2 files changed +8
-27
lines changed Expand file tree Collapse file tree 2 files changed +8
-27
lines changed Original file line number Diff line number Diff line change @@ -47,19 +47,13 @@ public function toArray(): array
47
47
];
48
48
}
49
49
50
- public function toCollect (bool $ asArray = false ): Collection
50
+ public function toCollect (): Collection
51
51
{
52
- $ hitsCollection = $ this ->getResult ()->getHits ();
52
+ $ hits = array_map (
53
+ fn (SearchHitDto $ searchHitDto ) => $ searchHitDto ->getSource (),
54
+ $ this ->getResult ()->getHits ()
55
+ );
53
56
54
- if ($ asArray ) {
55
- $ hits = array_map (
56
- fn (SearchHitDto $ searchHitDto ) => $ searchHitDto ->toArray (),
57
- $ hitsCollection
58
- );
59
-
60
- return Collection::make ($ hits );
61
- }
62
-
63
- return Collection::make ($ hitsCollection );
57
+ return Collection::make ($ hits );
64
58
}
65
59
}
Original file line number Diff line number Diff line change @@ -678,21 +678,8 @@ public function testSearchResponseCanBeConvertedToCollection(): void
678
678
679
679
$ this ->assertInstanceOf (Collection::class, $ result ->toCollect ());
680
680
681
- /** @var SearchHitDto $hit */
682
- foreach ($ result ->toCollect () as $ hit ) {
683
- $ this ->assertSame ('hello ' , $ hit ->getIndex ());
684
- $ this ->assertSame ('183865906814918156 ' , $ hit ->getId ());
685
- $ this ->assertSame (1.0 , $ hit ->getScore ());
686
- $ this ->assertSame (['hello ' => 'world ' ], $ hit ->getSource ());
687
- }
688
-
689
- $ this ->assertInstanceOf (Collection::class, $ result ->toCollect (asArray: true ));
690
-
691
- foreach ($ result ->toCollect (asArray: true ) as $ hit ) {
692
- $ this ->assertSame ('hello ' , $ hit ['index ' ]);
693
- $ this ->assertSame ('183865906814918156 ' , $ hit ['id ' ]);
694
- $ this ->assertSame (1.0 , $ hit ['score ' ]);
695
- $ this ->assertSame (['hello ' => 'world ' ], $ hit ['source ' ]);
681
+ foreach ($ result ->toCollect () as $ source ) {
682
+ $ this ->assertSame (['hello ' => 'world ' ], $ source );
696
683
}
697
684
}
698
685
}
You can’t perform that action at this time.
0 commit comments