-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathSearchIndexCommand.php
More file actions
92 lines (78 loc) · 2.63 KB
/
SearchIndexCommand.php
File metadata and controls
92 lines (78 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
/*
* UserFrosting Learn (http://www.userfrosting.com)
*
* @link https://github.com/userfrosting/Learn
* @copyright Copyright (c) 2025 Alexander Weissman & Louis Charette
* @license https://github.com/userfrosting/Learn/blob/main/LICENSE.md (MIT License)
*/
namespace UserFrosting\Learn\Bakery;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use UserFrosting\Bakery\WithSymfonyStyle;
use UserFrosting\Learn\Search\SearchIndex;
/**
* Bakery command to rebuild the search index for documentation.
*/
class SearchIndexCommand extends Command
{
use WithSymfonyStyle;
/**
* @param SearchIndex $searchIndex
*/
public function __construct(
protected SearchIndex $searchIndex,
) {
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
$this->setName('search:index')
->setDescription('Build or rebuild the search index for documentation')
->addOption(
'doc-version',
null,
InputOption::VALUE_OPTIONAL,
'Documentation version to index (omit to index all versions)'
)
->addOption(
'clear',
null,
InputOption::VALUE_NONE,
'Clear the search index before rebuilding'
);
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->io->title('Documentation Search Index');
/** @var string|null $version */
$version = $input->getOption('doc-version');
$clear = $input->getOption('clear');
// Clear index if requested
if ($clear === true) {
$this->io->writeln('Clearing search index...');
$this->searchIndex->clearIndex($version);
$this->io->success('Search index cleared.');
}
// Build index
$versionText = $version !== null ? "version {$version}" : 'all versions';
$this->io->writeln("Building search index for {$versionText}...");
try {
$count = $this->searchIndex->buildIndex($version);
$this->io->success("Search index built successfully. Indexed {$count} pages.");
} catch (\Exception $e) {
$this->io->error("Failed to build search index: {$e->getMessage()}");
return Command::FAILURE;
}
return Command::SUCCESS;
}
}