Files
Phraseanet/lib/Alchemy/Phrasea/Command/SearchEngine/IndexPopulateCommand.php
Jean-Yves Gaulier cf40c99ea7 PHRAS-714_thesaurus_indexation
- new : if the thesaurus has been modified since it's last indexation, it will be re-indexed as soon a record is to be indexed.
 - nb : after thesaurus modification, the databox MUST be manually re-indexed (which will reindex the thesaurus before)
 - todo : remove useless dialog boxes from thesaurus app (... "this term was..."  "...add with/out reindexing ?..."). To be done in the future app using future routes.
2016-10-12 18:42:16 +02:00

72 lines
2.1 KiB
PHP

<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2014 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\SearchEngine;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\SearchEngine\Elastic\Indexer;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class IndexPopulateCommand extends Command
{
protected function configure()
{
$this
->setName('searchengine:index:populate')
->setDescription('Populate search index')
->addOption(
'thesaurus',
null,
InputOption::VALUE_NONE,
'Only populate thesaurus data'
)
->addOption(
'records',
null,
InputOption::VALUE_NONE,
'Only populate record data'
)
->addOption(
'databox_id',
null,
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Only populate chosen databox'
)
;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$what = Indexer::THESAURUS | Indexer::RECORDS;
if ($thesaurusOnly = $input->getOption('thesaurus')) {
$what = Indexer::THESAURUS;
}
if ($recordsOnly = $input->getOption('records')) {
$what = Indexer::RECORDS;
}
if ($thesaurusOnly && $recordsOnly) {
throw new \RuntimeException("Could not provide --thesaurus and --records option at the same time.");
}
$databoxes_id = $input->getOption('databox_id');
$app = $this->container;
foreach($app->getDataboxes() as $databox) {
if(!$databoxes_id || in_array($databox->get_sbas_id(), $databoxes_id)) {
$this->container['elasticsearch.indexer']->populateIndex($what, $databox);
}
}
}
}