Skip to content

Commit 478c6a0

Browse files
committed
test: multi search
1 parent 4baaa8c commit 478c6a0

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

tests/Feature/MultiSearchTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Feature;
4+
5+
use Tests\TestCase;
6+
use Typesense\Exceptions\RequestMalformed;
7+
8+
class MultiSearchTest extends TestCase
9+
{
10+
private $searchRequests = [
11+
'searches' => [
12+
[
13+
'q' => 'book 1',
14+
],
15+
[
16+
'q' => 'book 2'
17+
]
18+
]
19+
];
20+
private $commonSearchParams = [
21+
'query_by' => 'title',
22+
'collection' => 'books',
23+
];
24+
25+
protected function setUp(): void
26+
{
27+
parent::setUp();
28+
29+
$this->setUpCollection('books');
30+
$this->setUpDocuments('books');
31+
}
32+
33+
public function testCanPerformAMultiSearch(): void
34+
{
35+
$returnData = $this->client()->multiSearch->perform($this->searchRequests, $this->commonSearchParams);
36+
$this->assertEquals(2, count($returnData['results']));
37+
}
38+
39+
public function testCanLimitNumberOfRequestsInOneMultiSearch(): void
40+
{
41+
$searchRequests = [
42+
'searches' => [
43+
...$this->searchRequests['searches'],
44+
[
45+
'q' => 'book 3'
46+
]
47+
]
48+
];
49+
50+
$this->expectException(RequestMalformed::class);
51+
$this->client()->multiSearch->perform($searchRequests, [
52+
"limit_multi_searches" => 2,
53+
...$this->commonSearchParams
54+
]);
55+
}
56+
}

0 commit comments

Comments
 (0)