Skip to content

Commit

Permalink
feat: outputs the channel for the cli commandos
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 22, 2024
1 parent be69fb5 commit 9f986eb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,23 @@ services:

Atoolo\Search\Console\Command\Indexer:
arguments:
- '@atoolo.resource.resourceChannelFactory'
- '@atoolo.search.indexer.progressBar'
- '@atoolo.search.indexer.internalResourceIndexer'

Atoolo\Search\Console\Command\Search:
arguments:
- '@atoolo.resource.resourceChannelFactory'
- '@atoolo.search.search'

Atoolo\Search\Console\Command\Suggest:
arguments:
- '@atoolo.resource.resourceChannelFactory'
- '@atoolo.search.suggest'

Atoolo\Search\Console\Command\MoreLikeThis:
arguments:
- '@atoolo.resource.resourceChannelFactory'
- '@atoolo.search.moreLikeThis'


Expand Down
7 changes: 7 additions & 0 deletions src/Console/Command/DumpIndexDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atoolo\Search\Console\Command;

use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Service\Indexer\IndexDocumentDumper;
use JsonException;
Expand All @@ -12,6 +13,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

#[AsCommand(
name: 'atoolo:dump-index-document',
Expand All @@ -20,6 +22,7 @@
class DumpIndexDocument extends Command
{
public function __construct(
private readonly ResourceChannelFactory $channelFactory,
private readonly IndexDocumentDumper $dumper
) {
parent::__construct();
Expand Down Expand Up @@ -49,6 +52,10 @@ protected function execute(

$paths = $typedInput->getArrayArgument('paths');

$resourceChannel = $this->channelFactory->create();
$io = new SymfonyStyle($input, $output);
$io->title('Channel: ' . $resourceChannel->name);

$dump = $this->dumper->dump($paths);

foreach ($dump as $fields) {
Expand Down
9 changes: 7 additions & 2 deletions src/Console/Command/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atoolo\Search\Console\Command;

use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\IndexerProgressBar;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Indexer\IndexerParameter;
Expand All @@ -25,6 +26,7 @@ class Indexer extends Command
private OutputInterface $output;

public function __construct(
private readonly ResourceChannelFactory $channelFactory,
private readonly IndexerProgressBar $progressBar,
private readonly InternalResourceIndexer $indexer,
) {
Expand Down Expand Up @@ -78,10 +80,13 @@ protected function execute(
? $typedInput->getIntOption('cleanup-threshold')
: 0;

$resourceChannel = $this->channelFactory->create();
$this->io->title('Channel: ' . $resourceChannel->name);

if (empty($paths)) {
$this->io->title('Index all resources');
$this->io->section('Index all resources');
} else {
$this->io->title('Index resource paths');
$this->io->section('Index resource paths');
$this->io->listing($paths);
}

Expand Down
5 changes: 5 additions & 0 deletions src/Console/Command/MoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atoolo\Search\Console\Command;

use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Search\Query\MoreLikeThisQuery;
use Atoolo\Search\Dto\Search\Result\SearchResult;
Expand All @@ -25,6 +26,7 @@ class MoreLikeThis extends Command
private TypifiedInput $input;

public function __construct(
private readonly ResourceChannelFactory $channelFactory,
private readonly SolrMoreLikeThis $searcher
) {
parent::__construct();
Expand Down Expand Up @@ -61,6 +63,9 @@ protected function execute(
$location = $this->input->getStringArgument('location');
$lang = $this->input->getStringOption('lang');

$resourceChannel = $this->channelFactory->create();
$this->io->title('Channel: ' . $resourceChannel->name);

$query = $this->buildQuery($location, $lang);
$result = $this->searcher->moreLikeThis($query);
$this->outputResult($result);
Expand Down
9 changes: 7 additions & 2 deletions src/Console/Command/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atoolo\Search\Console\Command;

use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Search\Query\SearchQuery;
use Atoolo\Search\Dto\Search\Query\SearchQueryBuilder;
Expand All @@ -26,6 +27,7 @@ class Search extends Command
private TypifiedInput $input;

public function __construct(
private readonly ResourceChannelFactory $channelFactory,
private readonly SolrSearch $searcher
) {
parent::__construct();
Expand Down Expand Up @@ -58,6 +60,9 @@ protected function execute(
$this->input = new TypifiedInput($input);
$this->io = new SymfonyStyle($input, $output);

$resourceChannel = $this->channelFactory->create();
$this->io->title('Channel: ' . $resourceChannel->name);

$query = $this->buildQuery($input);

$result = $this->searcher->search($query);
Expand Down Expand Up @@ -90,13 +95,13 @@ protected function outputResult(
return;
}

$this->io->title('Results (' . $result->total . ')');
$this->io->section('Results (' . $result->total . ')');
foreach ($result as $resource) {
$this->io->text($resource->getLocation());
}

if (count($result->facetGroups) > 0) {
$this->io->title('Facets');
$this->io->section('Facets');
foreach ($result->facetGroups as $facetGroup) {
$this->io->section($facetGroup->key);
$listing = [];
Expand Down
5 changes: 5 additions & 0 deletions src/Console/Command/Suggest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Atoolo\Search\Console\Command;

use Atoolo\Resource\ResourceChannelFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Search\Query\Filter\ArchiveFilter;
use Atoolo\Search\Dto\Search\Query\Filter\ObjectTypeFilter;
Expand All @@ -27,6 +28,7 @@ class Suggest extends Command
private SymfonyStyle $io;

public function __construct(
private readonly ResourceChannelFactory $channelFactory,
private readonly SolrSuggest $search
) {
parent::__construct();
Expand Down Expand Up @@ -60,6 +62,9 @@ protected function execute(
$terms = $this->input->getStringArgument('terms');
$lang = $this->input->getStringOption('lang');

$resourceChannel = $this->channelFactory->create();
$this->io->title('Channel: ' . $resourceChannel->name);

$query = $this->buildQuery($terms, $lang);

$result = $this->search->suggest($query);
Expand Down

0 comments on commit 9f986eb

Please sign in to comment.