From 4bcc03256c54b7e8631f1b8e6c3bb91f748cce2a Mon Sep 17 00:00:00 2001 From: Robert Brown Date: Thu, 6 Jun 2024 11:17:20 +0200 Subject: [PATCH] much better uuid to id query in opensearch. --- app/Services/StatementSearchService.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Services/StatementSearchService.php b/app/Services/StatementSearchService.php index d13cfe63..419e5cad 100644 --- a/app/Services/StatementSearchService.php +++ b/app/Services/StatementSearchService.php @@ -76,6 +76,9 @@ public function __construct(private readonly Client $client) } /** + * + * @param array $filters + * @param array $options * * @return Builder */ @@ -618,14 +621,14 @@ public function pushOSAKey($key): void public function uuidToId(string $uuid): int { + $uuid = str_replace("-", " ", $uuid); // replace the - with ' ' $query = [ "size" => 1, "query" => [ - "bool" => [ - "must" => [ - "match" => [ - "uuid" => $uuid - ] + "match" => [ + "uuid" => [ + "query" => $uuid, + "operator" => "and" ] ] ], @@ -636,6 +639,14 @@ public function uuidToId(string $uuid): int "excludes" => [] ] ]; + + $result = $this->client->search([ + 'index' => $this->index_name, + 'body' => $query, + ]); + + return $result['hits']['hits'][0]['_source']['id'] ?? 0; + } public function PlatformIdPuidToId(int $platform_id, string $puid): int