Skip to content

Improve distinct attribute search tests #754

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 17 additions & 3 deletions tests/Endpoints/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,25 @@ public function testSearchWithDistinctAttribute(): void

$response = $this->index->search(null, [
'distinct' => 'genre',
'filter' => ['genre = fantasy'],
])->toArray();

self::assertArrayHasKey('title', $response['hits'][0]);
self::assertCount(1, $response['hits']);
// Should have one document per unique genre
// From DOCUMENTS: romance, adventure, fantasy, plus one document without genre
self::assertCount(4, $response['hits']);

// Extract genres from the results
$genres = [];
foreach ($response['hits'] as $hit) {
$genre = $hit['genre'] ?? null;
self::assertNotContains($genre, $genres, 'Each genre should appear only once in distinct results');
$genres[] = $genre;
}

// Verify we have the expected unique genres
$expectedGenres = ['romance', 'adventure', 'fantasy', null];
foreach ($expectedGenres as $expectedGenre) {
self::assertContains($expectedGenre, $genres, "Genre '{$expectedGenre}' should be present in distinct results");
}
}

public function testSearchWithLocales(): void
Expand Down
Loading