Browse Source

add new fields index

main
ghost 9 months ago
parent
commit
5663adcb4c
  1. 70
      src/Manticore.php

70
src/Manticore.php

@ -12,6 +12,12 @@ class Manticore
private \Manticoresearch\Client $_client; private \Manticoresearch\Client $_client;
private \Manticoresearch\Index $_index; private \Manticoresearch\Index $_index;
private const OP_KEVA_NAMESPACE = 1;
private const OP_KEVA_PUT = 2;
private const OP_KEVA_DELETE = 3;
private const OP_HASH160 = 4;
private const OP_NOP = 5;
public function __construct( public function __construct(
?string $name = 'kvazar', ?string $name = 'kvazar',
?array $meta = [], ?array $meta = [],
@ -47,6 +53,18 @@ class Manticore
[ [
'type' => 'int' 'type' => 'int'
], ],
'operation' =>
[
'type' => 'int'
],
'time' =>
[
'type' => 'int'
],
'size' =>
[
'type' => 'int'
],
'block' => 'block' =>
[ [
'type' => 'int' 'type' => 'int'
@ -74,26 +92,34 @@ class Manticore
} }
public function add( public function add(
int $time,
int $size,
int $block, int $block,
string $namespace, string $namespace,
string $transaction, string $transaction,
string $operation,
string $key, string $key,
string $value string $value
) { ) {
return $this->_index->addDocument( return $this->_index->addDocument(
[ [
'crc32namespace' => crc32( 'crc32namespace' => $this->_crc32(
$namespace $namespace
), ),
'crc32transaction' => crc32( 'crc32transaction' => $this->_crc32(
$transaction $transaction
), ),
'crc32key' => crc32( 'crc32key' => $this->_crc32(
$key $key
), ),
'crc32value' => crc32( 'crc32value' => $this->_crc32(
$value $value
), ),
'operation' => $this->_operation(
$operation
),
'time' => $time,
'size' => $size,
'block' => $block, 'block' => $block,
'namespace' => $namespace, 'namespace' => $namespace,
'transaction' => $transaction, 'transaction' => $transaction,
@ -103,11 +129,41 @@ class Manticore
); );
} }
public function drop( public function drop(?bool $silent = false)
?bool $silent = false {
) {
return $this->_index->drop( return $this->_index->drop(
$silent $silent
); );
} }
private function _crc32(mixed $value): int
{
return crc32(
$value
);
}
private function _operation(string $value): int
{
switch ($value)
{
case 'OP_KEVA_NAMESPACE':
return self::OP_KEVA_NAMESPACE;
case 'OP_KEVA_PUT':
return self::OP_KEVA_PUT;
case 'OP_KEVA_DELETE':
return self::OP_KEVA_DELETE;
case 'OP_HASH160':
return self::OP_HASH160;
case 'OP_NOP':
return self::OP_NOP;
default:
return 0;
}
}
} }
Loading…
Cancel
Save