Skip to content

Commit 846a7f5

Browse files
authored
Merge pull request #308 from norkunas/fix-nbResults
Fix using bundle configured `nbResults` for search
2 parents 164b127 + f862b94 commit 846a7f5

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public function getConfigTreeBuilder(): TreeBuilder
2222
->scalarNode('prefix')
2323
->defaultNull()
2424
->end()
25-
->scalarNode('nbResults')
25+
->integerNode('nbResults')
2626
->defaultValue(20)
2727
->end()
28-
->scalarNode('batchSize')
28+
->integerNode('batchSize')
2929
->defaultValue(500)
3030
->end()
3131
->arrayNode('doctrineSubscribedEvents')

src/Services/MeilisearchService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function search(
155155
): array {
156156
$this->assertIsSearchable($className);
157157

158-
$ids = $this->engine->search($query, $this->searchableAs($className), $searchParams);
158+
$ids = $this->engine->search($query, $this->searchableAs($className), $searchParams + ['limit' => $this->configuration['nbResults']]);
159159
$results = [];
160160

161161
// Check if the engine returns results in "hits" key

tests/Integration/SearchTest.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Meilisearch\Bundle\Tests\Entity\Post;
1111
use Meilisearch\Bundle\Tests\Entity\Tag;
1212
use Meilisearch\Endpoints\Indexes;
13-
use Meilisearch\Exceptions\ApiException;
1413
use Symfony\Bundle\FrameworkBundle\Console\Application;
1514
use Symfony\Component\Console\Tester\CommandTester;
1615

@@ -26,10 +25,6 @@ class SearchTest extends BaseKernelTestCase
2625
protected Application $application;
2726
protected Indexes $index;
2827

29-
/**
30-
* @throws ApiException
31-
* @throws \Exception
32-
*/
3328
protected function setUp(): void
3429
{
3530
parent::setUp();
@@ -115,8 +110,20 @@ public function testSearchPagination(): void
115110
$this->assertEqualsCanonicalizing(array_slice($testDataTitles, 2, 2), $resultTitles);
116111
}
117112

118-
protected function tearDown(): void
113+
public function testSearchNbResults(): void
119114
{
120-
parent::tearDown();
115+
for ($i = 0; $i < 15; ++$i) {
116+
$this->createPost();
117+
}
118+
119+
$command = $this->application->find('meilisearch:import');
120+
$commandTester = new CommandTester($command);
121+
$commandTester->execute([
122+
'--indices' => $this->index->getUid(),
123+
]);
124+
125+
$results = $this->searchService->search($this->objectManager, Post::class, 'test');
126+
127+
$this->assertCount(12, $results);
121128
}
122129
}

0 commit comments

Comments
 (0)