-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from hkulekci/scroll-implementation
sort implementation for scroll endpoint
- Loading branch information
Showing
4 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
tests/Integration/Endpoints/Collections/SearchSortTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
/** | ||
* @since Mar 2023 | ||
* @author Haydar KULEKCI <[email protected]> | ||
*/ | ||
|
||
namespace Integration\Endpoints\Collections; | ||
|
||
use Qdrant\Endpoints\Collections; | ||
use Qdrant\Exception\InvalidArgumentException; | ||
use Qdrant\Models\Filter\Condition\MatchString; | ||
use Qdrant\Models\Filter\Filter; | ||
use Qdrant\Models\PointsStruct; | ||
use Qdrant\Models\Request\CreateIndex; | ||
use Qdrant\Models\Request\ScrollRequest; | ||
use Qdrant\Models\Request\SearchRequest; | ||
use Qdrant\Models\VectorStruct; | ||
use Qdrant\Tests\Integration\AbstractIntegration; | ||
|
||
class SearchSortTest extends AbstractIntegration | ||
{ | ||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->createCollections('sample-collection'); | ||
|
||
$response = $this->getCollections('sample-collection')->index()->create( | ||
(new CreateIndex('sort', [ | ||
'type' => 'integer', | ||
'range' => true, | ||
'lookup' => false, | ||
'is_principal' => true | ||
])), | ||
[ | ||
'wait' => 'true' | ||
] | ||
); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
$this->assertEquals('completed', $response['result']['status']); | ||
|
||
$response = $this->getCollections('sample-collection')->points() | ||
->upsert( | ||
PointsStruct::createFromArray(self::basicPointDataProvider()[0][0]), | ||
[ | ||
'wait' => 'true' | ||
] | ||
); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
$this->assertEquals('completed', $response['result']['status']); | ||
} | ||
|
||
public static function basicPointDataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
[ | ||
[ | ||
'id' => 1, | ||
'vector' => new VectorStruct([1, 3, 400], 'image'), | ||
'payload' => [ | ||
'sort' => 1, | ||
'color' => 'red' | ||
] | ||
], | ||
[ | ||
'id' => 2, | ||
'vector' => new VectorStruct([1, 3, 300], 'image'), | ||
'payload' => [ | ||
'sort' => 2, | ||
'color' => 'red' | ||
] | ||
], | ||
[ | ||
'id' => 3, | ||
'vector' => new VectorStruct([1, 3, 300], 'image'), | ||
'payload' => [ | ||
'sort' => 3, | ||
'color' => 'green' | ||
] | ||
], | ||
] | ||
] | ||
]; | ||
} | ||
|
||
public function testScrollAscPoint(): void | ||
{ | ||
$filter = (new Filter())->addMust( | ||
new MatchString('color', 'red') | ||
); | ||
|
||
$scroll = (new ScrollRequest())->setFilter($filter)->setOrderBy('sort'); | ||
$response = $this->getCollections('sample-collection')->points()->scroll($scroll); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
$this->assertCount(2, $response['result']); | ||
$this->assertEquals(1, $response['result']['points'][0]['id']); | ||
} | ||
|
||
public function testScrollDescPoint(): void | ||
{ | ||
$filter = (new Filter())->addMust( | ||
new MatchString('color', 'red') | ||
); | ||
|
||
$scroll = (new ScrollRequest())->setFilter($filter)->setOrderBy([ | ||
'key' => 'sort', | ||
'direction' => 'desc' | ||
]); | ||
$response = $this->getCollections('sample-collection')->points()->scroll($scroll); | ||
|
||
$this->assertEquals('ok', $response['status']); | ||
$this->assertCount(2, $response['result']); | ||
$this->assertEquals(2, $response['result']['points'][0]['id']); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
$collections = new Collections($this->client); | ||
|
||
$collections->setCollectionName('sample-collection')->delete(); | ||
} | ||
} |