Handle linter errors, add missing changes in TagFinder

This commit is contained in:
buchmann 2025-10-07 09:41:55 +02:00
parent 3a3ad1e147
commit adf95f6f84
3 changed files with 20 additions and 15 deletions

View file

@ -140,8 +140,8 @@ class SelectAPIController extends AbstractController
#[Route(path: '/tag', name: 'select_tag')] #[Route(path: '/tag', name: 'select_tag')]
public function getResponseForTags(EntityManagerInterface $entityManager): Response public function getResponseForTags(EntityManagerInterface $entityManager): Response
{ {
$tf = new TagFinder($entityManager, ['min_keyword_length' => 2, 'query_limit' => 250]); $tf = new TagFinder($entityManager);
$list = $tf->listTags('__'); // return every tag with at least two characters! $list = $tf->listTags('__', ['min_keyword_length' => 2, 'query_limit' => 250]); // return every tag with at least two characters!
$entries = []; $entries = [];

View file

@ -94,7 +94,7 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
} }
return new RedirectResponse( return new RedirectResponse(
$this->urlGenerator->generate($target_id !== 0 && $target_id !== null ? 'label_dialog_profile' : 'label_dialog', [ $this->urlGenerator->generate($target_id !== null && intval($target_id) !== 0 ? 'label_dialog_profile' : 'label_dialog', [
'profile' => $target_id, 'profile' => $target_id,
'target_id' => $targets, 'target_id' => $targets,
'generate' => '1', 'generate' => '1',
@ -107,7 +107,7 @@ implode(',', array_map(static fn (PartLot $lot) => $lot->getID(), $part->getPart
$matches = []; $matches = [];
if (preg_match('/^export_(json|yaml|xml|csv)$/', $action, $matches)) { if (preg_match('/^export_(json|yaml|xml|csv)$/', $action, $matches)) {
$ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts)); $ids = implode(',', array_map(static fn (Part $part) => $part->getID(), $selected_parts));
$level = match ($target_id) { $level = match (intval($target_id)) {
2 => 'extended', 2 => 'extended',
3 => 'full', 3 => 'full',
default => 'simple', default => 'simple',

View file

@ -50,7 +50,21 @@ class TagFinder
{ {
$results = []; $results = [];
$keyword_regex = '/^'.preg_quote($keyword, '/').'/'; $keyword_regex = '/^'.preg_quote($keyword, '/').'/';
$possible_tags = $this->listTags($keyword, $options);
//Iterate over each possible tags (which are comma separated) and extract tags which match our keyword
foreach ($possible_tags as $tags) {
$tags = explode(',', (string) $tags['tags']);
$results = array_merge($results, preg_grep($keyword_regex, $tags));
}
$results = array_unique($results);
//Limit the returned tag count to specified value.
return array_slice($results, 0, $options['return_limit']);
}
public function listTags(string $keyword, array $options = []): array
{
$resolver = new OptionsResolver(); $resolver = new OptionsResolver();
$this->configureOptions($resolver); $this->configureOptions($resolver);
@ -71,19 +85,10 @@ class TagFinder
//->orderBy('RAND()') //->orderBy('RAND()')
->setParameter(1, '%'.$keyword.'%'); ->setParameter(1, '%'.$keyword.'%');
$possible_tags = $qb->getQuery()->getArrayResult(); return $qb->getQuery()->getArrayResult();
//Iterate over each possible tags (which are comma separated) and extract tags which match our keyword
foreach ($possible_tags as $tags) {
$tags = explode(',', (string) $tags['tags']);
$results = array_merge($results, preg_grep($keyword_regex, $tags));
}
$results = array_unique($results);
//Limit the returned tag count to specified value.
return array_slice($results, 0, $options['return_limit']);
} }
protected function configureOptions(OptionsResolver $resolver): void protected function configureOptions(OptionsResolver $resolver): void
{ {
$resolver->setDefaults([ $resolver->setDefaults([