Skip to content

Commit 07cbae6

Browse files
committed
feat: implement doctrine-based fulltext search
Signed-off-by: Benjamin Frueh <benjamin.frueh@gmail.com>
1 parent 2b92d5a commit 07cbae6

23 files changed

+920
-558
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"league/commonmark": "^2.7",
2020
"symfony/string": "^6.0",
2121
"symfony/translation-contracts": "^3.6",
22-
"teamtnt/tntsearch": "^5.0"
22+
"wamania/php-stemmer": "^4.0"
2323
},
2424
"require-dev": {
2525
"ext-dom": "*",

composer.lock

Lines changed: 99 additions & 103 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/BackgroundJob/IndexCollectives.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use OCA\Collectives\Db\Collective;
1313
use OCA\Collectives\Db\CollectiveMapper;
1414
use OCA\Collectives\Mount\CollectiveFolderManager;
15+
use OCA\Collectives\Search\FileSearch\Db\SearchFileMapper;
1516
use OCA\Collectives\Search\FileSearch\FileSearchException;
1617
use OCA\Collectives\Service\SearchService;
1718
use OCP\AppFramework\Utility\ITimeFactory;
@@ -25,6 +26,7 @@ public function __construct(
2526
ITimeFactory $time,
2627
private CollectiveMapper $collectiveMapper,
2728
private CollectiveFolderManager $collectiveFolderManager,
29+
private SearchFileMapper $fileMapper,
2830
private LoggerInterface $logger,
2931
private SearchService $searchService,
3032
) {
@@ -37,10 +39,6 @@ public function __construct(
3739
* @param $argument
3840
*/
3941
protected function run($argument): void {
40-
if (!$this->searchService->areDependenciesMet()) {
41-
return;
42-
}
43-
4442
$collectives = $this->collectiveMapper->getAll();
4543
foreach ($collectives as $collective) {
4644
if ($this->isOutdatedIndex($collective)) {
@@ -57,14 +55,12 @@ protected function run($argument): void {
5755
}
5856

5957
private function isOutdatedIndex(Collective $collective): bool {
60-
$index = $this->searchService->getIndexForCollective($collective);
61-
if (!$index) {
62-
return true;
63-
}
64-
6558
try {
6659
$folder = $this->collectiveFolderManager->getRootFolder()->get((string)$collective->getId());
67-
return $folder->getMTime() > $index->getMTime();
60+
$folderMtime = $folder->getMTime();
61+
$maxIndexedMtime = $this->fileMapper->getMaxMtimeByCircle($collective->getCircleId());
62+
63+
return $maxIndexedMtime === null || $folderMtime > $maxIndexedMtime;
6864
} catch (NotFoundException|InvalidPathException) {
6965
return false;
7066
}

lib/Command/IndexCollectives.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Command\Command;
1919
use Symfony\Component\Console\Input\InputArgument;
2020
use Symfony\Component\Console\Input\InputInterface;
21+
use Symfony\Component\Console\Input\InputOption;
2122
use Symfony\Component\Console\Output\OutputInterface;
2223

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

3941
protected function execute(InputInterface $input, OutputInterface $output): int {
40-
if (!$this->searchService->areDependenciesMet()) {
41-
$output->writeln('<error>Could not index the collectives: PDO or SQLite extension not installed.</error>');
42-
return 1;
43-
}
44-
4542
$collectives = $this->collectiveMapper->getAll();
4643
$name = $input->getArgument('name');
44+
$fullIndex = $input->getOption('full');
4745

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

0 commit comments

Comments
 (0)