|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 7 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace OCA\FullTextSearch\Provider; |
| 11 | + |
| 12 | +use Generator; |
| 13 | +use NCU\FullTextSearch\Model\Document; |
| 14 | +use OCA\FullTextSearch\Files\Service\FilesService; |
| 15 | +use OCA\FullTextSearch\Files\Service\SharesService; |
| 16 | +use NCU\FullTextSearch\IContentProvider; |
| 17 | +use NCU\FullTextSearch\IContentProviderImprovedSearch; |
| 18 | +use NCU\FullTextSearch\IContentProviderSyncIndex; |
| 19 | +use NCU\FullTextSearch\IIndexQueryHelper; |
| 20 | +use NCU\FullTextSearch\Model\UnindexedDocument; |
| 21 | +use OCP\FullTextSearch\Model\ISearchRequest; |
| 22 | +use OCP\FullTextSearch\Model\ISearchResult; |
| 23 | +use OCP\FullTextSearch\Model\ISearchTemplate; |
| 24 | +use OCP\IDBConnection; |
| 25 | + |
| 26 | +class FilesContentProvider implements |
| 27 | + IContentProvider, |
| 28 | + IContentProviderSyncIndex, |
| 29 | + IContentProviderImprovedSearch { |
| 30 | + public function __construct( |
| 31 | + private readonly IDBConnection $connection, |
| 32 | + private readonly FilesService $filesService, |
| 33 | + private readonly SharesService $sharesService, |
| 34 | + ) { |
| 35 | + } |
| 36 | + |
| 37 | + public function getId(): string { |
| 38 | + return 'files'; |
| 39 | + } |
| 40 | + |
| 41 | + public function getConfiguration(): array { |
| 42 | + return []; |
| 43 | + } |
| 44 | + |
| 45 | + public function getDocument(string $documentId): ?Document { |
| 46 | + $nodeId = (int)$documentId; |
| 47 | + $node = $this->filesService->getNode($nodeId); |
| 48 | + if ($node === null) { |
| 49 | + return null; |
| 50 | + } |
| 51 | + |
| 52 | + return $this->filesService->generateDocument($node); |
| 53 | + } |
| 54 | + |
| 55 | + // IContentProviderImprovedSearch |
| 56 | + public function getSearchTemplate(): ?ISearchTemplate { |
| 57 | + return null; |
| 58 | + } |
| 59 | + |
| 60 | + // IContentProviderImprovedSearch |
| 61 | + public function improveSearchRequest(ISearchRequest $searchRequest): void { |
| 62 | + } |
| 63 | + |
| 64 | + // IContentProviderImprovedSearch |
| 65 | + public function improveSearchResult(ISearchResult $searchResult): void { |
| 66 | + } |
| 67 | + |
| 68 | + // IContentProviderSyncIndex |
| 69 | + public function getUnindexedDocuments(IIndexQueryHelper $qh): Generator { |
| 70 | + $qh->notNeeded(); |
| 71 | + $qb = $this->connection->getQueryBuilder(); |
| 72 | + $qb->select('fileid', 'mtime') |
| 73 | + ->from('filecache'); |
| 74 | + $result = $qb->executeQuery(); |
| 75 | + while ($row = $result->fetch()) { |
| 76 | + yield new UnindexedDocument($row['fileid'], $row['mtime']); |
| 77 | + } |
| 78 | + $result->closeCursor(); |
| 79 | + } |
| 80 | +} |
| 81 | + |
0 commit comments