From d41531526cf93a02320c01659907a64e2f44bf74 Mon Sep 17 00:00:00 2001 From: Yoan Bozhilov Date: Wed, 17 Jun 2026 10:25:21 +0300 Subject: [PATCH] feat(command): add context_chat:reindex to re-seed the crawl on demand The SchedulerJob -> StorageCrawlJob -> IndexerJob chain is seeded only by the repair step and self-removes after the initial crawl, so there is no way to re-enumerate mounts without reinstalling the app (e.g. after installing on an instance whose files predate the app, or to recover an incomplete crawl). Add an occ command that re-adds SchedulerJob (no-op if already scheduled); already-indexed files are skipped by the queue de-duplication. Refs #244 Signed-off-by: Yoan Bozhilov Assisted-by: Claude Code:claude-opus-4-8 --- appinfo/info.xml | 1 + lib/Command/Reindex.php | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 lib/Command/Reindex.php diff --git a/appinfo/info.xml b/appinfo/info.xml index 941ac62d..a1c960ab 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -50,6 +50,7 @@ Refer to the [Context Chat Backend's readme](https://github.com/nextcloud/contex OCA\ContextChat\Command\Prompt OCA\ContextChat\Command\Search OCA\ContextChat\Command\Statistics + OCA\ContextChat\Command\Reindex diff --git a/lib/Command/Reindex.php b/lib/Command/Reindex.php new file mode 100644 index 00000000..c6906a5c --- /dev/null +++ b/lib/Command/Reindex.php @@ -0,0 +1,51 @@ + StorageCrawlJob -> IndexerJob is seeded only by the repair step and + * removes itself once the initial crawl finishes. There is otherwise no way to re-enumerate + * mounts (e.g. after installing on an instance whose files predate the app, or to recover a crawl + * that did not complete) short of reinstalling the app. This command re-adds SchedulerJob so the + * full enumeration runs again; it is a no-op if one is already scheduled, and already-indexed + * files are skipped (the queue de-duplicates). + */ +class Reindex extends Command { + + public function __construct( + private IJobList $jobList, + ) { + parent::__construct(); + } + + protected function configure() { + $this->setName('context_chat:reindex') + ->setDescription('Schedule a full re-crawl of all mounts (re-seeds the indexing chain; indexed files are skipped)'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int { + if ($this->jobList->has(SchedulerJob::class, null)) { + $output->writeln('A full re-crawl is already scheduled; nothing to do.'); + return 0; + } + + $this->jobList->add(SchedulerJob::class); + $output->writeln('Scheduled a full re-crawl. SchedulerJob will enumerate all mounts on its next run.'); + return 0; + } +}