Skip to content

Commit b2b867a

Browse files
committed
fix: Uuid incompatibility
1 parent 99d88d6 commit b2b867a

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ composer.lock
44
composer.phar
55
.php_cs
66
.php_cs.cache
7-
.phpunit.result.cache
7+
.phpunit.result.cache
8+
.idea

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"php-http/curl-client": "^2.2",
1919
"monolog/monolog": "^2.3|^3.0",
2020
"symfony/property-access": "^3.4|^4.3|^5|^6.0|^7.0",
21-
"symfony/http-client": "^5.4|^6.2|^7.0"
21+
"symfony/http-client": "^5.4|^6.2|^7.0",
22+
"ramsey/uuid": "^4.8"
2223
},
2324
"require-dev": {
2425
"symfony/phpunit-bridge": "^5.0|^6.0",

src/Finder/CollectionFinder.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use ACSEO\TypesenseBundle\Client\CollectionClient;
88
use Doctrine\ORM\EntityManagerInterface;
99
use Doctrine\ORM\Query\ResultSetMappingBuilder;
10+
use Ramsey\Uuid\UuidInterface;
1011

1112
class CollectionFinder implements CollectionFinderInterface
1213
{
@@ -18,7 +19,7 @@ public function __construct(CollectionClient $collectionClient, EntityManagerInt
1819
{
1920
$this->collectionConfig = $collectionConfig;
2021
$this->collectionClient = $collectionClient;
21-
$this->em = $em;
22+
$this->em = $em;
2223
}
2324

2425
public function rawQuery(TypesenseQuery $query)
@@ -33,7 +34,7 @@ public function query(TypesenseQuery $query): TypesenseResponse
3334
return $this->hydrate($results);
3435
}
3536

36-
public function hydrateResponse(TypesenseResponse $response) : TypesenseResponse
37+
public function hydrateResponse(TypesenseResponse $response): TypesenseResponse
3738
{
3839
return $this->hydrate($response);
3940
}
@@ -44,9 +45,9 @@ public function hydrateResponse(TypesenseResponse $response) : TypesenseResponse
4445
* @param TypesenseResponse $results
4546
* @return TypesenseResponse
4647
*/
47-
private function hydrate(TypesenseResponse $results) : TypesenseResponse
48+
private function hydrate(TypesenseResponse $results): TypesenseResponse
4849
{
49-
$ids = [];
50+
$ids = [];
5051
$primaryKeyInfos = $this->getPrimaryKeyInfo();
5152
foreach ($results->getResults() as $result) {
5253
$ids[] = $result['document'][$primaryKeyInfos['documentAttribute']];
@@ -73,6 +74,14 @@ private function hydrate(TypesenseResponse $results) : TypesenseResponse
7374
$idA = $a->$entityIdMethod();
7475
$idB = $b->$entityIdMethod();
7576

77+
if ($idA instanceof UuidInterface) {
78+
$idA = $idA->toString();
79+
}
80+
81+
if ($idB instanceof UuidInterface) {
82+
$idB = $idB->toString();
83+
}
84+
7685
return $idIndex[$idA] <=> $idIndex[$idB];
7786
});
7887

@@ -85,7 +94,7 @@ private function hydrate(TypesenseResponse $results) : TypesenseResponse
8594
return $results;
8695
}
8796

88-
private function search(TypesenseQuery $query) : TypesenseResponse
97+
private function search(TypesenseQuery $query): TypesenseResponse
8998
{
9099
$result = $this->collectionClient->search($this->collectionConfig['typesense_name'], $query);
91100

0 commit comments

Comments
 (0)