mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-10-20 20:12:39 +03:00
Added a formal object type to carry across vector search results. Added permission application and entity combining with vector search results. Also updated namespace from vectors to queries.
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
use BookStack\Entities\EntityProvider;
|
|
use BookStack\Entities\Models\Entity;
|
|
use BookStack\Search\Queries\SearchVector;
|
|
use BookStack\Search\Queries\StoreEntityVectorsJob;
|
|
use Illuminate\Console\Command;
|
|
|
|
class RegenerateVectorsCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'bookstack:regenerate-vectors';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Re-index vectors for all content in the system';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle(EntityProvider $entityProvider)
|
|
{
|
|
// TODO - Add confirmation before run regarding deletion/time/effort/api-cost etc...
|
|
SearchVector::query()->delete();
|
|
|
|
$types = $entityProvider->all();
|
|
foreach ($types as $type => $typeInstance) {
|
|
$this->info("Creating jobs to store vectors for {$type} data...");
|
|
/** @var Entity[] $entities */
|
|
$typeInstance->newQuery()->chunkById(100, function ($entities) {
|
|
foreach ($entities as $entity) {
|
|
dispatch(new StoreEntityVectorsJob($entity));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|