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

Fix using bundle configured nbResults for search #308

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('prefix')
->defaultNull()
->end()
->scalarNode('nbResults')
->integerNode('nbResults')
->defaultValue(20)
->end()
->scalarNode('batchSize')
->integerNode('batchSize')
->defaultValue(500)
->end()
->arrayNode('doctrineSubscribedEvents')
Expand Down
2 changes: 1 addition & 1 deletion src/Services/MeilisearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function search(
): array {
$this->assertIsSearchable($className);

$ids = $this->engine->search($query, $this->searchableAs($className), $searchParams);
$ids = $this->engine->search($query, $this->searchableAs($className), $searchParams + ['limit' => $this->configuration['nbResults']]);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we use an array_merge or something like that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No need :) test proves that:)

$results = [];

// Check if the engine returns results in "hits" key
Expand Down
21 changes: 14 additions & 7 deletions tests/Integration/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Meilisearch\Bundle\Tests\Entity\Post;
use Meilisearch\Bundle\Tests\Entity\Tag;
use Meilisearch\Endpoints\Indexes;
use Meilisearch\Exceptions\ApiException;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -26,10 +25,6 @@ class SearchTest extends BaseKernelTestCase
protected Application $application;
protected Indexes $index;

/**
* @throws ApiException
* @throws \Exception
*/
protected function setUp(): void
{
parent::setUp();
Expand Down Expand Up @@ -115,8 +110,20 @@ public function testSearchPagination(): void
$this->assertEqualsCanonicalizing(array_slice($testDataTitles, 2, 2), $resultTitles);
}

protected function tearDown(): void
public function testSearchNbResults(): void
{
parent::tearDown();
for ($i = 0; $i < 15; ++$i) {
$this->createPost();
}

$command = $this->application->find('meilisearch:import');
$commandTester = new CommandTester($command);
$commandTester->execute([
'--indices' => $this->index->getUid(),
]);

$results = $this->searchService->search($this->objectManager, Post::class, 'test');

$this->assertCount(12, $results);
}
}
Loading