Skip to content
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

Add sorting of results #12

Merged
merged 6 commits into from
Aug 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Some more search + sorting functional tests
  • Loading branch information
Zales0123 authored and loevgaard committed Aug 21, 2024
commit 221f7f66107310a7d3b71bfac1b3b9ef9edb9c41
38 changes: 38 additions & 0 deletions tests/Functional/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,42 @@ public function testItProvidesSearchResults(): void

self::assertSame(8, $result->getHitsCount());
}

public function testItSortsSearchResultsByLowestPrice(): void
{
$searchEngine = self::getContainer()->get(SearchEngine::class);
$result = $searchEngine->execute('jeans', ['sort' => 'price:asc']);

self::assertSame(8, $result->getHitsCount());

$previousKey = null;
foreach ($result->getHits() as $key => $hit) {
if ($previousKey === null) {
$previousKey = $key;
continue;
}

self::assertGreaterThanOrEqual($result->getHit($previousKey)['price'], $hit['price']);
$previousKey = $key;
}
}

public function testItSortsSearchResultsByNewestDate(): void
{
$searchEngine = self::getContainer()->get(SearchEngine::class);
$result = $searchEngine->execute('jeans', ['sort' => 'createdAt:desc']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This small thing createdAt:desc made me think about whether we should snake case properties inside Meilisearch? If there would ever be a problem with camel case? I am thinking about web servers ignoring case, browsers ignoring case or whatever. I don't know. Do any of you know? It will give a lot of other problems though :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it shouldn't make any troubles.


self::assertSame(8, $result->getHitsCount());

$previousKey = null;
foreach ($result->getHits() as $key => $hit) {
if ($previousKey === null) {
$previousKey = $key;
continue;
}

self::assertLessThanOrEqual($result->getHit($previousKey)['createdAt'], $hit['createdAt']);
$previousKey = $key;
}
}
}