Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 802413f754 | |||
| e56ea29018 | |||
| 3faec6370c | |||
| 361cd7baf8 | |||
| 6111bd07e5 | |||
| 76ab724d1a | |||
| d7a7d0b6e8 | |||
| 3f57c78d01 | |||
| e88da82267 | |||
|
|
709c641fc9 | ||
|
|
ff506e2aef | ||
|
|
702fe24be4 | ||
| 319334834b | |||
| 9bad1cb2b9 | |||
| df927a8197 | |||
| 5c98989631 | |||
| 373087a5d5 | |||
| 205b29e07c | |||
| e1d5f094de |
6
Makefile
6
Makefile
@@ -1,5 +1,7 @@
|
|||||||
PHP = docker compose run php
|
PHP = docker compose run php
|
||||||
|
|
||||||
|
.PHONY: composer_install composer_update static_analysis tests
|
||||||
|
|
||||||
composer_install:
|
composer_install:
|
||||||
@$(PHP) composer install
|
@$(PHP) composer install
|
||||||
|
|
||||||
@@ -8,3 +10,7 @@ composer_update:
|
|||||||
|
|
||||||
static_analysis:
|
static_analysis:
|
||||||
@$(PHP) vendor/bin/psalm
|
@$(PHP) vendor/bin/psalm
|
||||||
|
|
||||||
|
tests:
|
||||||
|
@$(PHP) rm -rf var/cache
|
||||||
|
@$(PHP) vendor/bin/phpunit
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
|
|
||||||
|
pcm_search.command.index:
|
||||||
|
class: Pcm\SearchBundle\Command\SearchIndexCommand
|
||||||
|
tags:
|
||||||
|
- { name: 'console.command', command: 'pcm:search:reindex' }
|
||||||
|
|
||||||
pcm_search.searchable_subscriber:
|
pcm_search.searchable_subscriber:
|
||||||
class: Pcm\SearchBundle\EventSubscriber\SearchableSubscriber
|
class: Pcm\SearchBundle\EventSubscriber\SearchableSubscriber
|
||||||
public: true
|
public: true
|
||||||
|
|||||||
13
phpunit.xml
13
phpunit.xml
@@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<phpunit colors="true" bootstrap="vendor/autoload.php">
|
|
||||||
<testsuites>
|
|
||||||
<testsuite name="Test Suite">
|
|
||||||
<directory suffix="Test.php">./tests/</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
|
||||||
<filter>
|
|
||||||
<whitelist>
|
|
||||||
<directory>./src</directory>
|
|
||||||
</whitelist>
|
|
||||||
</filter>
|
|
||||||
</phpunit>
|
|
||||||
19
phpunit.xml.dist
Normal file
19
phpunit.xml.dist
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="./vendor/autoload.php">
|
||||||
|
<coverage>
|
||||||
|
<include>
|
||||||
|
<directory>./src</directory>
|
||||||
|
</include>
|
||||||
|
</coverage>
|
||||||
|
<php>
|
||||||
|
<ini name="error_reporting" value="-1"/>
|
||||||
|
<ini name="intl.default_locale" value="en"/>
|
||||||
|
<ini name="intl.error_level" value="0"/>
|
||||||
|
<ini name="memory_limit" value="-1"/>
|
||||||
|
</php>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="Test suite">
|
||||||
|
<directory suffix="Test.php">./tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
namespace Pcm\SearchBundle\Command;
|
namespace Pcm\SearchBundle\Command;
|
||||||
|
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Pcm\SearchBundle\Entity\SearchIndex;
|
use Pcm\SearchBundle\Entity\SearchIndex;
|
||||||
use Pcm\SearchBundle\Service\SearchService;
|
use Pcm\SearchBundle\Service\SearchService;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Symfony\Component\Console\Helper\Table;
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Helper\ProgressBar;
|
use Symfony\Component\Console\Helper\ProgressBar;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Component\Console\Attribute\AsCommand;
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
@@ -23,7 +25,16 @@ class SearchIndexCommand extends Command
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure(): void {}
|
protected function configure(): void
|
||||||
|
{
|
||||||
|
$this->addOption(
|
||||||
|
'batchsize',
|
||||||
|
'b',
|
||||||
|
InputOption::VALUE_REQUIRED,
|
||||||
|
'Number of rows to process before flushing',
|
||||||
|
2000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
protected function execute(InputInterface $input, OutputInterface $output): int
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
{
|
{
|
||||||
@@ -42,29 +53,46 @@ class SearchIndexCommand extends Command
|
|||||||
$progress_bar->setProgressCharacter("<fg=green>➤</>");
|
$progress_bar->setProgressCharacter("<fg=green>➤</>");
|
||||||
$progress_bar->start();
|
$progress_bar->start();
|
||||||
|
|
||||||
|
$batchSize = $input->getOption('batchsize');
|
||||||
|
$searchEntities = null;
|
||||||
|
|
||||||
foreach ($searchables as $searchable) {
|
foreach ($searchables as $searchable) {
|
||||||
$entities = $this
|
$entities = $this
|
||||||
->em
|
->em
|
||||||
->getRepository($searchable)
|
->getRepository($searchable)
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
|
$searchEntities[] = [$searchable, count($entities)];
|
||||||
|
|
||||||
|
$this->em->clear();
|
||||||
|
$counter = 1;
|
||||||
|
|
||||||
foreach ($entities as $entity) {
|
foreach ($entities as $entity) {
|
||||||
$search_result = $this->searchService->createSearchResult($entity);
|
$search_result = $this->searchService->createSearchResult($entity);
|
||||||
|
|
||||||
$this->em->persist($search_result);
|
$this->em->persist($search_result);
|
||||||
|
|
||||||
|
if (($counter % $batchSize) === 0) {
|
||||||
|
$this->em->flush();
|
||||||
|
$this->em->clear();
|
||||||
|
}
|
||||||
|
$counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
$progress_bar->advance();
|
$progress_bar->advance();
|
||||||
}
|
|
||||||
|
|
||||||
$this->em->flush();
|
$this->em->flush();
|
||||||
|
$this->em->clear();
|
||||||
|
}
|
||||||
|
|
||||||
$progress_bar->finish();
|
$progress_bar->finish();
|
||||||
|
|
||||||
$io->writeln('');
|
$table = new Table($output);
|
||||||
$io->writeln('');
|
$table
|
||||||
|
->setHeaders(['Class', 'Count'])
|
||||||
|
->setRows($searchEntities)
|
||||||
|
;
|
||||||
|
$table->render();
|
||||||
|
|
||||||
|
$io->writeln('');
|
||||||
$io->success('Index updated');
|
$io->success('Index updated');
|
||||||
|
|
||||||
return Command::SUCCESS;
|
return Command::SUCCESS;
|
||||||
|
|||||||
@@ -6,11 +6,28 @@ namespace Pcm\SearchBundle\DependencyInjection;
|
|||||||
|
|
||||||
use Symfony\Component\Config\FileLocator;
|
use Symfony\Component\Config\FileLocator;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||||
|
|
||||||
class PcmSearchExtension extends Extension
|
class PcmSearchExtension extends Extension implements PrependExtensionInterface
|
||||||
{
|
{
|
||||||
|
public function prepend(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
$container->loadFromExtension(
|
||||||
|
'doctrine',
|
||||||
|
[
|
||||||
|
'orm' => [
|
||||||
|
'dql' => [
|
||||||
|
'string_functions' => [
|
||||||
|
'match' => 'DoctrineExtensions\Query\Mysql\MatchAgainst'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function load(array $configs, ContainerBuilder $container)
|
public function load(array $configs, ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$loader = new YamlFileLoader(
|
$loader = new YamlFileLoader(
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class SearchableSubscriber implements EventSubscriber
|
|||||||
{
|
{
|
||||||
public function __construct(private SearchService $searchService) {}
|
public function __construct(private SearchService $searchService) {}
|
||||||
|
|
||||||
public function getSubscribedEvents()
|
public function getSubscribedEvents(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
Events::postPersist,
|
Events::postPersist,
|
||||||
|
|||||||
Reference in New Issue
Block a user