File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -888,11 +888,25 @@ public function testSearchWithDistinctAttribute(): void
888888
889889 $ response = $ this ->index ->search (null , [
890890 'distinct ' => 'genre ' ,
891- 'filter ' => ['genre = fantasy ' ],
892891 ])->toArray ();
893892
894- self ::assertArrayHasKey ('title ' , $ response ['hits ' ][0 ]);
895- self ::assertCount (1 , $ response ['hits ' ]);
893+ // Should have one document per unique genre
894+ // From DOCUMENTS: romance, adventure, fantasy, plus one document without genre
895+ self ::assertCount (4 , $ response ['hits ' ]);
896+
897+ // Extract genres from the results
898+ $ genres = [];
899+ foreach ($ response ['hits ' ] as $ hit ) {
900+ $ genre = $ hit ['genre ' ] ?? null ;
901+ self ::assertNotContains ($ genre , $ genres , 'Each genre should appear only once in distinct results ' );
902+ $ genres [] = $ genre ;
903+ }
904+
905+ // Verify we have the expected unique genres
906+ $ expectedGenres = ['romance ' , 'adventure ' , 'fantasy ' , null ];
907+ foreach ($ expectedGenres as $ expectedGenre ) {
908+ self ::assertContains ($ expectedGenre , $ genres , "Genre ' {$ expectedGenre }' should be present in distinct results " );
909+ }
896910 }
897911
898912 public function testSearchWithLocales (): void
You can’t perform that action at this time.
0 commit comments