Skip to content

Commit 9b0ecd1

Browse files
authored
feat: add context_chat:reindex to re-seed the crawl on demand (#246)
* feat(command): add context_chat:reindex to re-seed the crawl on demand The SchedulerJob -> StorageCrawlJob -> IndexerJob chain is seeded only by the <install> 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 <bygadd@gmail.com> Assisted-by: Claude Code:claude-opus-4-8 * fix(command): apply review wording on reindex docstring and description Reword the class docstring and the command description per review feedback. Signed-off-by: Yoan Bozhilov <bygadd@gmail.com> Assisted-by: Claude Code:claude-opus-4-8
1 parent f3aa164 commit 9b0ecd1

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Refer to the [Context Chat Backend's readme](https://github.com/nextcloud/contex
5050
<command>OCA\ContextChat\Command\Prompt</command>
5151
<command>OCA\ContextChat\Command\Search</command>
5252
<command>OCA\ContextChat\Command\Statistics</command>
53+
<command>OCA\ContextChat\Command\Reindex</command>
5354
</commands>
5455
<repair-steps>
5556
<install>

lib/Command/Reindex.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\ContextChat\Command;
11+
12+
use OCA\ContextChat\BackgroundJobs\SchedulerJob;
13+
use OCP\BackgroundJob\IJobList;
14+
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Input\InputInterface;
16+
use Symfony\Component\Console\Output\OutputInterface;
17+
18+
/**
19+
* Re-seed the one-shot filesystem crawl/index on demand.
20+
*
21+
* SchedulerJob -> StorageCrawlJob -> IndexerJob is seeded only by the <install> repair step and
22+
* removes itself once the initial crawl finishes. There is otherwise no way to re-enumerate
23+
* mounts (e.g. after installing on an instance whose files predate the app, or to recover a crawl
24+
* that did not complete) short of reinstalling the app. This command re-adds SchedulerJob so the
25+
* full enumeration runs again; it is a no-op if one is already scheduled, and already-indexed
26+
* files are skipped.
27+
*/
28+
class Reindex extends Command {
29+
30+
public function __construct(
31+
private IJobList $jobList,
32+
) {
33+
parent::__construct();
34+
}
35+
36+
protected function configure() {
37+
$this->setName('context_chat:reindex')
38+
->setDescription('Schedule a full re-crawl of all mounts. Indexed files are not re-indexed when compared against context_chat_backend\'s vector DB.');
39+
}
40+
41+
protected function execute(InputInterface $input, OutputInterface $output): int {
42+
if ($this->jobList->has(SchedulerJob::class, null)) {
43+
$output->writeln('<comment>A full re-crawl is already scheduled; nothing to do.</comment>');
44+
return 0;
45+
}
46+
47+
$this->jobList->add(SchedulerJob::class);
48+
$output->writeln('<info>Scheduled a full re-crawl. SchedulerJob will enumerate all mounts on its next run.</info>');
49+
return 0;
50+
}
51+
}

0 commit comments

Comments
 (0)