Skip to content

Commit

Permalink
refactore: automatic index determination including multi-lang indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
sitepark-veltrup committed Mar 21, 2024
1 parent a81707a commit e10800d
Show file tree
Hide file tree
Showing 69 changed files with 782 additions and 1,117 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"symfony/lock": "^6.3 | ^7.0",
"symfony/property-access": "^6.3 | ^7.0",
"symfony/serializer": "^6.3 | ^7.0",
"symfony/yaml": "^6.3 | ^7.0"
},
"symfony/yaml": "^6.3 | ^7.0",
"ext-intl": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"infection/infection": "^0.27.6",
Expand Down
59 changes: 57 additions & 2 deletions config/commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,68 @@ services:
Atoolo\Search\Console\:
resource: '../src/Console'

Atoolo\Search\Console\Command\Indexer:
Atoolo\Search\Service\Indexer\IndexDocumentDumper:
arguments:
- '@atoolo.resource.resourceLoader'
- !tagged_iterator { tag: 'atoolo.search.indexer.documentEnricher.schema2x' }

Atoolo\Search\Console\Command\DumpIndexDocument:
arguments:
- !tagged_iterator { tag: 'atoolo.search.indexer.documentEnricher.schema2x' }
- '@Atoolo\Search\Service\Indexer\IndexDocumentDumper'

atoolo.search.indexer.progressBar:
class: 'Atoolo\Search\Console\Command\Io\IndexerProgressBar'

atoolo.search.indexer.internalResourceIndexer:
class: Atoolo\Search\Service\Indexer\InternalResourceIndexer
arguments:
- !tagged_iterator atoolo.search.indexer.documentEnricher.schema2x
- '@atoolo.search.indexer.progressBar'
- '@atoolo.search.indexer.locationFinder'
- '@atoolo.resource.resourceLoader'
- '@atoolo.search.indexer.translationSplitter'
- '@atoolo.search.indexer.solrIndexService'
- '@atoolo.search.indexer.aborter'
- 'internal'

atoolo.search.selectSearcher:
class: Atoolo\Search\Service\Search\SolrSelect
arguments:
- '@atoolo.search.indexName'
- '@atoolo.search.solariumClientFactory'
- !tagged_iterator atoolo.search.queryModifier
- '@atoolo.search.resultToResourceResolver'

atoolo.search.suggestSearcher:
class: Atoolo\Search\Service\Search\SolrSuggest
arguments:
- '@atoolo.search.indexName'
- '@atoolo.search.solariumClientFactory'

atoolo.search.moreLikeThisSearcher:
class: Atoolo\Search\Service\Search\SolrMoreLikeThis
arguments:
- '@atoolo.search.indexName'
- '@atoolo.search.solariumClientFactory'
- '@atoolo.search.resultToResourceResolver'

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

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

Atoolo\Search\Console\Command\Suggest:
arguments:
- '@atoolo.search.suggestSearcher'

Atoolo\Search\Console\Command\MoreLikeThis:
arguments:
- '@atoolo.search.moreLikeThisSearcher'


Atoolo\Search\Console\Application:
public: true
Expand Down
25 changes: 4 additions & 21 deletions src/Console/Command/DumpIndexDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
namespace Atoolo\Search\Console\Command;

use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Service\Indexer\DocumentEnricher;
use Atoolo\Search\Service\Indexer\IndexDocument;
use Atoolo\Search\Service\Indexer\IndexDocumentDumper;
use JsonException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
Expand All @@ -20,13 +19,8 @@
)]
class DumpIndexDocument extends Command
{
/**
* phpcs:ignore
* @param iterable<DocumentEnricher<IndexDocument>> $documentEnricherList
*/
public function __construct(
private readonly iterable $documentEnricherList,
private readonly IndexDocumentDumperBuilder $indexDocumentDumperBuilder
private readonly IndexDocumentDumper $dumper
) {
parent::__construct();
}
Expand All @@ -35,11 +29,6 @@ protected function configure(): void
{
$this
->setHelp('Command to dump a index-document')
->addArgument(
'resource-dir',
InputArgument::REQUIRED,
'Resource directory whose data is to be indexed.'
)
->addArgument(
'paths',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
Expand All @@ -58,15 +47,9 @@ protected function execute(

$typedInput = new TypifiedInput($input);

$resourceDir = $typedInput->getStringArgument('resource-dir');

$dumper = $this->indexDocumentDumperBuilder
->resourceDir($resourceDir)
->documentEnricherList($this->documentEnricherList)
->build();

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

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

foreach ($dump as $fields) {
$output->writeln(json_encode(
Expand Down
56 changes: 0 additions & 56 deletions src/Console/Command/IndexDocumentDumperBuilder.php

This file was deleted.

42 changes: 4 additions & 38 deletions src/Console/Command/Indexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
namespace Atoolo\Search\Console\Command;

use Atoolo\Search\Console\Command\Io\IndexerProgressBar;
use Atoolo\Search\Console\Command\Io\IndexerProgressBarFactory;
use Atoolo\Search\Console\Command\Io\TypifiedInput;
use Atoolo\Search\Dto\Indexer\IndexerParameter;
use Atoolo\Search\Service\Indexer\DocumentEnricher;
use Atoolo\Search\Service\Indexer\IndexDocument;
use Atoolo\Search\Service\Indexer\InternalResourceIndexer;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -23,18 +21,12 @@
)]
class Indexer extends Command
{
private IndexerProgressBar $progressBar;
private SymfonyStyle $io;
private OutputInterface $output;

/**
* phpcs:ignore
* @param iterable<DocumentEnricher<IndexDocument>> $documentEnricherList
*/
public function __construct(
private readonly iterable $documentEnricherList,
private readonly InternalResourceIndexerBuilder $solrIndexerBuilder,
private readonly IndexerProgressBarFactory $progressBarFactory
private readonly IndexerProgressBar $progressBar,
private readonly InternalResourceIndexer $indexer,
) {
parent::__construct();
}
Expand All @@ -43,21 +35,6 @@ protected function configure(): void
{
$this
->setHelp('Command to fill a search index')
->addArgument(
'solr-connection-url',
InputArgument::REQUIRED,
'Solr connection url.'
)
->addArgument(
'solr-core',
InputArgument::REQUIRED,
'Solr core to be used.'
)
->addArgument(
'resource-dir',
InputArgument::REQUIRED,
'Resource directory whose data is to be indexed.'
)
->addArgument(
'paths',
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
Expand Down Expand Up @@ -93,7 +70,6 @@ protected function execute(
$typedInput = new TypifiedInput($input);
$this->output = $output;
$this->io = new SymfonyStyle($input, $output);
$this->progressBar = $this->progressBarFactory->create($output);

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

Expand All @@ -109,22 +85,12 @@ protected function execute(
}

$parameter = new IndexerParameter(
$typedInput->getStringArgument('solr-core'),
$cleanupThreshold,
$typedInput->getIntOption('chunk-size'),
$paths
);

$this->solrIndexerBuilder
->resourceDir($typedInput->getStringArgument('resource-dir'))
->progressBar($this->progressBar)
->documentEnricherList($this->documentEnricherList)
->solrConnectionUrl(
$typedInput->getStringArgument('solr-connection-url')
);

$indexer = $this->solrIndexerBuilder->build();
$indexer->index($parameter);
$this->indexer->index($parameter);

$this->errorReport();

Expand Down
Loading

0 comments on commit e10800d

Please sign in to comment.