From 3373b57d1e90ac3fb617319a9ceb9ffcc13a6577 Mon Sep 17 00:00:00 2001 From: ghost Date: Mon, 12 Feb 2024 23:33:03 +0200 Subject: [PATCH] implement index:get method --- src/Manticore.php | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/Manticore.php b/src/Manticore.php index 4f19371..a380c60 100644 --- a/src/Manticore.php +++ b/src/Manticore.php @@ -131,6 +131,61 @@ class Manticore ); } + public function get( + ?string $search = '', + ?array $filter = [], + ?array $sort = ['id' => 'desc'], + ?int $offset = 0, + ?int $limit = 2 + ): array + { + $records = []; + + $search = $this->_index->search( + $search + ); + + foreach ($filter as $key => $value) + { + $search->filter( + $key, + $value + ); + } + + foreach ($sort as $key => $value) + { + $search->sort( + $key, + $value + ); + } + + $search->offset( + $offset + ); + + $search->limit( + $limit + ); + + foreach ($search->get() as $record) + { + $records[$record->getId()] = + [ + 'time' => $record->get('time'), + 'size' => $record->get('size'), + 'block' => $record->get('block'), + 'namespace' => $record->get('namespace'), + 'transaction' => $record->get('transaction'), + 'key' => $record->get('key'), + 'value' => $record->get('value') + ]; + } + + return $records; + } + public function drop(?bool $silent = false) { return $this->_index->drop(