mirror of
https://github.com/YGGverse/Yo.git
synced 2025-03-11 04:41:02 +00:00
implement alter index tool
This commit is contained in:
parent
44e2836de4
commit
36972cab19
11
README.md
11
README.md
@ -67,6 +67,17 @@ php src/cli/index/init.php [reset]
|
|||||||
```
|
```
|
||||||
* `reset` - optional, reset existing index
|
* `reset` - optional, reset existing index
|
||||||
|
|
||||||
|
##### Alter
|
||||||
|
|
||||||
|
Change existing index
|
||||||
|
|
||||||
|
```
|
||||||
|
php src/cli/index/alter.php {operation} {column} {type}
|
||||||
|
```
|
||||||
|
* `operation` - operation name, supported values: `add`|`drop`
|
||||||
|
* `column` - target column name
|
||||||
|
* `type` - target column type, supported values: `text`|`integer`
|
||||||
|
|
||||||
#### Document
|
#### Document
|
||||||
|
|
||||||
##### Add
|
##### Add
|
||||||
|
@ -1,4 +1,99 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// @TODO
|
// Load dependencies
|
||||||
// https://github.com/manticoresoftware/manticoresearch-php/blob/master/docs/indexclass.md#alter
|
require_once __DIR__ . '/../../../vendor/autoload.php';
|
||||||
|
|
||||||
|
// Init config
|
||||||
|
$config = json_decode(
|
||||||
|
file_get_contents(
|
||||||
|
__DIR__ . '/../../../config.json'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init client
|
||||||
|
$client = new \Manticoresearch\Client(
|
||||||
|
[
|
||||||
|
'host' => $config->manticore->server->host,
|
||||||
|
'port' => $config->manticore->server->port,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Init index
|
||||||
|
$index = $client->index(
|
||||||
|
$config->manticore->index->document->name
|
||||||
|
);
|
||||||
|
|
||||||
|
// Validate request
|
||||||
|
if (empty($argv[1]))
|
||||||
|
{
|
||||||
|
exit(
|
||||||
|
_('Operation name required!') . PHP_EOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($argv[2]))
|
||||||
|
{
|
||||||
|
exit(
|
||||||
|
_('Operated column required!') . PHP_EOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($argv[1] == 'add')
|
||||||
|
{
|
||||||
|
if (empty($argv[3]))
|
||||||
|
{
|
||||||
|
exit(
|
||||||
|
_('Operated column type required!') . PHP_EOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!in_array($argv[3], ['integer', 'text']))
|
||||||
|
{
|
||||||
|
exit(
|
||||||
|
_('Undefined column type!') . PHP_EOL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Route query
|
||||||
|
switch ($argv[1])
|
||||||
|
{
|
||||||
|
case 'add':
|
||||||
|
|
||||||
|
if ($result = $index->alter($argv[1], $argv[2], $argv[3]))
|
||||||
|
{
|
||||||
|
echo sprintf(
|
||||||
|
'row "%s" with type "%s" successfully added to index "%s" with result: %s' . PHP_EOL,
|
||||||
|
$argv[2],
|
||||||
|
$argv[3],
|
||||||
|
$config->manticore->index->document->name,
|
||||||
|
print_r(
|
||||||
|
$result,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'drop':
|
||||||
|
|
||||||
|
if ($result = $index->alter($argv[1], $argv[2]))
|
||||||
|
{
|
||||||
|
echo sprintf(
|
||||||
|
'row "%s" successfully deleted from index "%s" with result: %s' . PHP_EOL,
|
||||||
|
$argv[2],
|
||||||
|
$config->manticore->index->document->name,
|
||||||
|
print_r(
|
||||||
|
$result,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
|
echo _('Unknown operation!') . PHP_EOL;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user