Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"league/commonmark": "^2.7",
"symfony/string": "^6.0",
"symfony/translation-contracts": "^3.6",
"teamtnt/tntsearch": "^5.0"
"wamania/php-stemmer": "^4.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use this one in a few other apps: https://github.com/search?q=org%3Anextcloud+wamania%2Fphp-stemmer&type=code

Maybe worth to consider scoping the dependency to avoid conflicts with different versions between apps. https://arthur-schiwon.de/isolating-nextcloud-app-dependencies-php-scoper

},
"require-dev": {
"ext-dom": "*",
Expand Down
202 changes: 99 additions & 103 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 6 additions & 10 deletions lib/BackgroundJob/IndexCollectives.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\Collectives\Db\Collective;
use OCA\Collectives\Db\CollectiveMapper;
use OCA\Collectives\Mount\CollectiveFolderManager;
use OCA\Collectives\Search\FileSearch\Db\SearchFileMapper;
use OCA\Collectives\Search\FileSearch\FileSearchException;
use OCA\Collectives\Service\SearchService;
use OCP\AppFramework\Utility\ITimeFactory;
Expand All @@ -25,6 +26,7 @@ public function __construct(
ITimeFactory $time,
private CollectiveMapper $collectiveMapper,
private CollectiveFolderManager $collectiveFolderManager,
private SearchFileMapper $fileMapper,
private LoggerInterface $logger,
private SearchService $searchService,
) {
Expand All @@ -37,10 +39,6 @@ public function __construct(
* @param $argument
*/
protected function run($argument): void {
if (!$this->searchService->areDependenciesMet()) {
return;
}

$collectives = $this->collectiveMapper->getAll();
foreach ($collectives as $collective) {
if ($this->isOutdatedIndex($collective)) {
Expand All @@ -57,14 +55,12 @@ protected function run($argument): void {
}

private function isOutdatedIndex(Collective $collective): bool {
$index = $this->searchService->getIndexForCollective($collective);
if (!$index) {
return true;
}

try {
$folder = $this->collectiveFolderManager->getRootFolder()->get((string)$collective->getId());
return $folder->getMTime() > $index->getMTime();
$folderMtime = $folder->getMTime();
$maxIndexedMtime = $this->fileMapper->getMaxMtimeByCircle($collective->getCircleId());

return $maxIndexedMtime === null || $folderMtime > $maxIndexedMtime;
} catch (NotFoundException|InvalidPathException) {
return false;
}
Expand Down
12 changes: 5 additions & 7 deletions lib/Command/IndexCollectives.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class IndexCollectives extends Command {
Expand All @@ -32,18 +33,15 @@ protected function configure(): void {
$this
->setName('collectives:index')
->setDescription('Indexes collectives for full text search.')
->addArgument('name', InputArgument::OPTIONAL, 'name of new collective');
->addArgument('name', InputArgument::OPTIONAL, 'name of new collective')
->addOption('full', 'f', InputOption::VALUE_NONE, 'Full re-index (default: incremental)');
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int {
if (!$this->searchService->areDependenciesMet()) {
$output->writeln('<error>Could not index the collectives: PDO or SQLite extension not installed.</error>');
return 1;
}

$collectives = $this->collectiveMapper->getAll();
$name = $input->getArgument('name');
$fullIndex = $input->getOption('full');

foreach ($collectives as $collective) {
try {
Expand All @@ -53,7 +51,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}
$output->write('<info>Creating index for ' . $circleName . ' …</info>');
$this->searchService->indexCollective($collective);
$this->searchService->indexCollective($collective, !$fullIndex);
$output->writeln('<info>done</info>');
} catch (MissingDependencyException|NotFoundException|NotPermittedException) {
$output->writeln("<error>Failed to find team associated with collective with ID={$collective->getId()}</error>");
Expand Down
Loading
Loading