Skip to content

Commit c897df4

Browse files
committed
query param improvement for payload delete and point search endpoints hkulekci#8
1 parent aed17be commit c897df4

5 files changed

Lines changed: 54 additions & 7 deletions

File tree

src/Endpoints/Collections/Points.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public function payload(): Payload
3131
/**
3232
* @throws InvalidArgumentException
3333
*/
34-
public function search(SearchRequest $searchParams): Response
34+
public function search(SearchRequest $searchParams, array $queryParams = []): Response
3535
{
3636
return $this->client->execute(
3737
$this->createRequest(
3838
'POST',
39-
'collections/' . $this->collectionName . '/points/search',
39+
'collections/' . $this->collectionName . '/points/search' . $this->queryBuild($queryParams),
4040
$searchParams->toArray()
4141
)
4242
);

src/Endpoints/Collections/Points/Payload.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function clear(array $points): Response
4040
* @return Response
4141
* @throws InvalidArgumentException
4242
*/
43-
public function delete(array $points, array $keys, Filter $filter = null): Response
43+
public function delete(array $points, array $keys, Filter $filter = null, array $queryParams = []): Response
4444
{
4545
$data = [
4646
'points' => $points,
@@ -53,7 +53,7 @@ public function delete(array $points, array $keys, Filter $filter = null): Respo
5353
return $this->client->execute(
5454
$this->createRequest(
5555
'POST',
56-
'/collections/' . $this->getCollectionName() . '/points/payload/delete',
56+
'/collections/' . $this->getCollectionName() . '/points/payload/delete' . $this->queryBuild($queryParams),
5757
$data
5858
)
5959
);
@@ -62,12 +62,12 @@ public function delete(array $points, array $keys, Filter $filter = null): Respo
6262
/**
6363
* @throws InvalidArgumentException
6464
*/
65-
public function set(array $points, array $payload, array $params = []): Response
65+
public function set(array $points, array $payload, array $queryParams = []): Response
6666
{
6767
return $this->client->execute(
6868
$this->createRequest(
6969
'POST',
70-
'/collections/' . $this->getCollectionName() . '/points/payload' . $this->queryBuild($params),
70+
'/collections/' . $this->getCollectionName() . '/points/payload' . $this->queryBuild($queryParams),
7171
[
7272
'payload' => $payload,
7373
'points' => $points,

tests/Integration/Endpoints/Collections/ClusterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testClusterUpdate(): void
4343
$response = $cluster->update([
4444
"move_shard" => [
4545
"shard_id" => 0,
46-
"to_peer_id" => 0,
46+
"to_peer_id" => 1,
4747
"from_peer_id" => 0
4848
]
4949
]);

tests/Integration/Endpoints/Collections/Points/PayloadTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ public function testDeletePayloadForPoint(array $pointsArray): void
109109
$this->assertEmpty($response['result']['payload']);
110110
}
111111

112+
/**
113+
* @throws InvalidArgumentException
114+
* @dataProvider basicPointDataProvider
115+
*/
116+
public function testDeletePayloadForPointWithQueryParams(array $pointsArray): void
117+
{
118+
$collections = new Collections($this->client);
119+
120+
$response = $collections->setCollectionName('sample-collection')->create(self::sampleCollectionOption());
121+
$this->assertEquals('ok', $response['status'], 'Collection Could Not Created!');
122+
$points = $collections->setCollectionName('sample-collection')->points();
123+
$points->upsert(PointsStruct::createFromArray($pointsArray));
124+
125+
$payload = $collections->setCollectionName('sample-collection')->points()->payload();
126+
$payload->delete([2], ['image'], null, ['wait' => 'true', 'ordering' => 'strong']);
127+
128+
$response = $points->id(2);
129+
$this->assertArrayHasKey('result', $response);
130+
$this->assertArrayHasKey('payload', $response['result']);
131+
$this->assertEmpty($response['result']['payload']);
132+
}
133+
112134
/**
113135
* @throws InvalidArgumentException
114136
* @dataProvider basicPointDataProvider

tests/Integration/Endpoints/Collections/SearchTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ public function testSearchPoint(VectorStruct $vector): void
8383
$this->assertCount(1, $response['result']);
8484
}
8585

86+
87+
/**
88+
* @dataProvider searchQueryProvider
89+
*/
90+
public function testSearchPointWithQueryParams(VectorStruct $vector): void
91+
{
92+
$searchRequest = (new SearchRequest($vector))
93+
->setLimit(3)
94+
->setFilter(
95+
(new Filter())->addMust(
96+
new MatchString('image', 'sample image')
97+
)
98+
)
99+
->setParams([
100+
'hnsw_ef' => 128,
101+
'exact' => false,
102+
]);
103+
104+
$response = $this->getCollections('sample-collection')
105+
->points()->search($searchRequest, ['timeout' => 1, 'consistency' => 'all']);
106+
107+
$this->assertEquals('ok', $response['status']);
108+
$this->assertCount(1, $response['result']);
109+
}
110+
86111
/**
87112
* @dataProvider searchQueryProvider
88113
*/

0 commit comments

Comments
 (0)