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 @@ -12,6 +12,12 @@ class Manticore
private \Manticoresearch\Client $_client;
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(
?string $name = 'kvazar',
?array $meta = [],
@ -47,6 +53,18 @@ class Manticore @@ -47,6 +53,18 @@ class Manticore
[
'type' => 'int'
],
'operation' =>
[
'type' => 'int'
],
'time' =>
[
'type' => 'int'
],
'size' =>
[
'type' => 'int'
],
'block' =>
[
'type' => 'int'
@ -74,26 +92,34 @@ class Manticore @@ -74,26 +92,34 @@ class Manticore
}
public function add(
int $time,
int $size,
int $block,
string $namespace,
string $transaction,
string $operation,
string $key,
string $value
) {
return $this->_index->addDocument(
[
'crc32namespace' => crc32(
'crc32namespace' => $this->_crc32(
$namespace
),
'crc32transaction' => crc32(
'crc32transaction' => $this->_crc32(
$transaction
),
'crc32key' => crc32(
'crc32key' => $this->_crc32(
$key
),
'crc32value' => crc32(
'crc32value' => $this->_crc32(
$value
),
'operation' => $this->_operation(
$operation
),
'time' => $time,
'size' => $size,
'block' => $block,
'namespace' => $namespace,
'transaction' => $transaction,
@ -103,11 +129,41 @@ class Manticore @@ -103,11 +129,41 @@ class Manticore
);
}
public function drop(
?bool $silent = false
) {
public function drop(?bool $silent = false)
{
return $this->_index->drop(
$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