Merge pull request #45950 from nextcloud/chore/remove-depreacted-search

chore: Remove deprecated legacy search backend
pull/46918/head
Andy Scherzinger 2024-08-01 13:56:09 +07:00 committed by GitHub
commit 014fcb0131
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 0 additions and 812 deletions

@ -13,7 +13,6 @@ use OCA\Comments\Listener\LoadSidebarScripts;
use OCA\Comments\MaxAutoCompleteResultsInitialState;
use OCA\Comments\Notification\Notifier;
use OCA\Comments\Search\CommentsSearchProvider;
use OCA\Comments\Search\LegacyProvider;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCP\AppFramework\App;
@ -22,7 +21,6 @@ use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Comments\CommentsEntityEvent;
use OCP\Comments\CommentsEvent;
use OCP\ISearch;
class Application extends App implements IBootstrap {
public const APP_ID = 'comments';
@ -59,6 +57,5 @@ class Application extends App implements IBootstrap {
}
public function boot(IBootContext $context): void {
$context->getServerContainer()->get(ISearch::class)->registerProvider(LegacyProvider::class, ['apps' => ['files']]);
}
}

@ -9,7 +9,6 @@ declare(strict_types=1);
namespace OCA\Files\AppInfo;
use Closure;
use OC\Search\Provider\File;
use OCA\Files\Capabilities;
use OCA\Files\Collaboration\Resources\Listener;
use OCA\Files\Collaboration\Resources\ResourceProvider;
@ -45,7 +44,6 @@ use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\IConfig;
use OCP\IPreview;
use OCP\IRequest;
use OCP\ISearch;
use OCP\IServerContainer;
use OCP\ITagManager;
use OCP\IUserSession;
@ -127,7 +125,6 @@ class Application extends App implements IBootstrap {
public function boot(IBootContext $context): void {
$context->injectFn(Closure::fromCallable([$this, 'registerCollaboration']));
$context->injectFn([Listener::class, 'register']);
$context->injectFn(Closure::fromCallable([$this, 'registerSearchProvider']));
$this->registerTemplates();
$this->registerHooks();
}
@ -136,10 +133,6 @@ class Application extends App implements IBootstrap {
$providerManager->registerResourceProvider(ResourceProvider::class);
}
private function registerSearchProvider(ISearch $search): void {
$search->registerProvider(File::class, ['apps' => ['files']]);
}
private function registerTemplates(): void {
$templateManager = \OC_Helper::getFileTemplateManager();
$templateManager->registerTemplate('application/vnd.oasis.opendocument.presentation', 'core/templates/filetemplates/template.odp');

@ -1,273 +0,0 @@
# SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
Feature: comments-search
Scenario: Search my own comment on a file belonging to myself
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "My first comment" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "first" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | My first comment |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My first comment |
Scenario: Search my own comment on a file shared by someone with me
Given user "user0" exists
And user "user1" exists
And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt"
And as "user1" creating a share with
| path | sharedFileToComment.txt |
| shareWith | user0 |
| shareType | 0 |
And user "user0" accepts last share
And "user0" posts a comment with content "My first comment" on the file named "/sharedFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "first" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | My first comment |
| authorId | user0 |
| authorName | user0 |
| path | sharedFileToComment.txt |
| fileName | sharedFileToComment.txt |
| name | My first comment |
Scenario: Search other user's comment on a file shared by me
Given user "user0" exists
And user "user1" exists
And User "user0" uploads file "data/textfile.txt" to "/mySharedFileToComment.txt"
And as "user0" creating a share with
| path | mySharedFileToComment.txt |
| shareWith | user1 |
| shareType | 0 |
And user "user1" accepts last share
And "user1" posts a comment with content "Other's first comment" on the file named "/mySharedFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "first" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | Other's first comment |
| authorId | user1 |
| authorName | user1 |
| path | mySharedFileToComment.txt |
| fileName | mySharedFileToComment.txt |
| name | Other's first comment |
Scenario: Search other user's comment on a file shared by someone with me
Given user "user0" exists
And user "user1" exists
And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt"
And as "user1" creating a share with
| path | sharedFileToComment.txt |
| shareWith | user0 |
| shareType | 0 |
And user "user0" accepts last share
And "user1" posts a comment with content "Other's first comment" on the file named "/sharedFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "first" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | Other's first comment |
| authorId | user1 |
| authorName | user1 |
| path | sharedFileToComment.txt |
| fileName | sharedFileToComment.txt |
| name | Other's first comment |
Scenario: Search several comments on a file belonging to myself
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "My first comment to be found" on the file named "/myFileToComment.txt" it should return "201"
And "user0" posts a comment with content "The second comment should not be found" on the file named "/myFileToComment.txt" it should return "201"
And "user0" posts a comment with content "My third comment to be found" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "comment to be found" in app "files"
Then the list of search results has "2" results
And search result "0" contains
| type | comment |
| comment | My third comment to be found |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My third comment to be found |
And search result "1" contains
| type | comment |
| comment | My first comment to be found |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My first comment to be found |
Scenario: Search comment with a large message ellipsized on the right
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "verbose" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | A very verbose message that is meant to |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments |
Scenario: Search comment with a large message ellipsized on the left
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "searching" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | ed message returned when searching for long comments |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments |
Scenario: Search comment with a large message ellipsized on both ends
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "ellipsized" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | t to be used to test the ellipsized message returned when se |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | A very verbose message that is meant to be used to test the ellipsized message returned when searching for long comments |
Scenario: Search comment on a file in a subfolder
Given user "user0" exists
And user "user0" created a folder "/subfolder"
And User "user0" uploads file "data/textfile.txt" to "/subfolder/myFileToComment.txt"
And "user0" posts a comment with content "My first comment" on the file named "/subfolder/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "first" in app "files"
Then the list of search results has "1" results
And search result "0" contains
| type | comment |
| comment | My first comment |
| authorId | user0 |
| authorName | user0 |
| path | subfolder/myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My first comment |
Scenario: Search several comments
Given user "user0" exists
And user "user1" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And User "user0" uploads file "data/textfile.txt" to "/mySharedFileToComment.txt"
And as "user0" creating a share with
| path | mySharedFileToComment.txt |
| shareWith | user1 |
| shareType | 0 |
And user "user1" accepts last share
And User "user1" uploads file "data/textfile.txt" to "/sharedFileToComment.txt"
And as "user1" creating a share with
| path | sharedFileToComment.txt |
| shareWith | user0 |
| shareType | 0 |
And user "user0" accepts last share
And "user0" posts a comment with content "My first comment to be found" on the file named "/myFileToComment.txt" it should return "201"
And "user0" posts a comment with content "The second comment should not be found" on the file named "/myFileToComment.txt" it should return "201"
And "user0" posts a comment with content "My first comment to be found" on the file named "/mySharedFileToComment.txt" it should return "201"
And "user1" posts a comment with content "Other's first comment that should not be found" on the file named "/mySharedFileToComment.txt" it should return "201"
And "user1" posts a comment with content "Other's second comment to be found" on the file named "/mySharedFileToComment.txt" it should return "201"
And "user0" posts a comment with content "My first comment that should not be found" on the file named "/sharedFileToComment.txt" it should return "201"
And "user1" posts a comment with content "Other's first comment to be found" on the file named "/sharedFileToComment.txt" it should return "201"
And "user0" posts a comment with content "My second comment to be found that happens to be more verbose than the others and thus should be ellipsized" on the file named "/sharedFileToComment.txt" it should return "201"
And "user0" posts a comment with content "My third comment to be found" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "comment to be found" in app "files"
Then the list of search results has "6" results
And search result "0" contains
| type | comment |
| comment | My third comment to be found |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My third comment to be found |
And search result "1" contains
| type | comment |
| comment | My second comment to be found that happens to be more |
| authorId | user0 |
| authorName | user0 |
| path | sharedFileToComment.txt |
| fileName | sharedFileToComment.txt |
| name | My second comment to be found that happens to be more verbose than the others and thus should be ellipsized |
And search result "2" contains
| type | comment |
| comment | Other's first comment to be found |
| authorId | user1 |
| authorName | user1 |
| path | sharedFileToComment.txt |
| fileName | sharedFileToComment.txt |
| name | Other's first comment to be found |
And search result "3" contains
| type | comment |
| comment | Other's second comment to be found |
| authorId | user1 |
| authorName | user1 |
| path | mySharedFileToComment.txt |
| fileName | mySharedFileToComment.txt |
| name | Other's second comment to be found |
And search result "4" contains
| type | comment |
| comment | My first comment to be found |
| authorId | user0 |
| authorName | user0 |
| path | mySharedFileToComment.txt |
| fileName | mySharedFileToComment.txt |
| name | My first comment to be found |
And search result "5" contains
| type | comment |
| comment | My first comment to be found |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | My first comment to be found |
Scenario: Search comment with a query that also matches a file name
Given user "user0" exists
And User "user0" uploads file "data/textfile.txt" to "/myFileToComment.txt"
And "user0" posts a comment with content "A comment in myFileToComment.txt" on the file named "/myFileToComment.txt" it should return "201"
When Logging in using web as "user0"
And searching for "myFileToComment" in app "files"
Then the list of search results has "2" results
And search result "0" contains
| type | file |
| path | /myFileToComment.txt |
| name | myFileToComment.txt |
And search result "1" contains
| type | comment |
| comment | A comment in myFileToComment.txt |
| authorId | user0 |
| authorName | user0 |
| path | myFileToComment.txt |
| fileName | myFileToComment.txt |
| name | A comment in myFileToComment.txt |

@ -1,46 +0,0 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Controller;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use OCP\ISearch;
use OCP\Search\Result;
use Psr\Log\LoggerInterface;
class SearchController extends Controller {
public function __construct(
string $appName,
IRequest $request,
private ISearch $searcher,
private LoggerInterface $logger,
) {
parent::__construct($appName, $request);
}
#[NoAdminRequired]
#[FrontpageRoute(verb: 'GET', url: '/core/search')]
public function search(string $query, array $inApps = [], int $page = 1, int $size = 30): JSONResponse {
$results = $this->searcher->searchPaged($query, $inApps, $page, $size);
$results = array_filter($results, function (Result $result) {
if (json_encode($result, JSON_HEX_TAG) === false) {
$this->logger->warning("Skipping search result due to invalid encoding: {type: " . $result->type . ", id: " . $result->id . "}");
return false;
} else {
return true;
}
});
return new JSONResponse($results);
}
}

@ -537,7 +537,6 @@ return array(
'OCP\\IPreview' => $baseDir . '/lib/public/IPreview.php',
'OCP\\IRequest' => $baseDir . '/lib/public/IRequest.php',
'OCP\\IRequestId' => $baseDir . '/lib/public/IRequestId.php',
'OCP\\ISearch' => $baseDir . '/lib/public/ISearch.php',
'OCP\\IServerContainer' => $baseDir . '/lib/public/IServerContainer.php',
'OCP\\ISession' => $baseDir . '/lib/public/ISession.php',
'OCP\\IStreamImage' => $baseDir . '/lib/public/IStreamImage.php',
@ -1265,7 +1264,6 @@ return array(
'OC\\Core\\Controller\\RecommendedAppsController' => $baseDir . '/core/Controller/RecommendedAppsController.php',
'OC\\Core\\Controller\\ReferenceApiController' => $baseDir . '/core/Controller/ReferenceApiController.php',
'OC\\Core\\Controller\\ReferenceController' => $baseDir . '/core/Controller/ReferenceController.php',
'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php',
'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php',
'OC\\Core\\Controller\\TaskProcessingApiController' => $baseDir . '/core/Controller/TaskProcessingApiController.php',
'OC\\Core\\Controller\\TeamsApiController' => $baseDir . '/core/Controller/TeamsApiController.php',
@ -1813,7 +1811,6 @@ return array(
'OC\\Route\\CachingRouter' => $baseDir . '/lib/private/Route/CachingRouter.php',
'OC\\Route\\Route' => $baseDir . '/lib/private/Route/Route.php',
'OC\\Route\\Router' => $baseDir . '/lib/private/Route/Router.php',
'OC\\Search' => $baseDir . '/lib/private/Search.php',
'OC\\Search\\FilterCollection' => $baseDir . '/lib/private/Search/FilterCollection.php',
'OC\\Search\\FilterFactory' => $baseDir . '/lib/private/Search/FilterFactory.php',
'OC\\Search\\Filter\\BooleanFilter' => $baseDir . '/lib/private/Search/Filter/BooleanFilter.php',
@ -1824,11 +1821,6 @@ return array(
'OC\\Search\\Filter\\StringFilter' => $baseDir . '/lib/private/Search/Filter/StringFilter.php',
'OC\\Search\\Filter\\StringsFilter' => $baseDir . '/lib/private/Search/Filter/StringsFilter.php',
'OC\\Search\\Filter\\UserFilter' => $baseDir . '/lib/private/Search/Filter/UserFilter.php',
'OC\\Search\\Provider\\File' => $baseDir . '/lib/private/Search/Provider/File.php',
'OC\\Search\\Result\\Audio' => $baseDir . '/lib/private/Search/Result/Audio.php',
'OC\\Search\\Result\\File' => $baseDir . '/lib/private/Search/Result/File.php',
'OC\\Search\\Result\\Folder' => $baseDir . '/lib/private/Search/Result/Folder.php',
'OC\\Search\\Result\\Image' => $baseDir . '/lib/private/Search/Result/Image.php',
'OC\\Search\\SearchComposer' => $baseDir . '/lib/private/Search/SearchComposer.php',
'OC\\Search\\SearchQuery' => $baseDir . '/lib/private/Search/SearchQuery.php',
'OC\\Search\\UnsupportedFilter' => $baseDir . '/lib/private/Search/UnsupportedFilter.php',

@ -570,7 +570,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\IPreview' => __DIR__ . '/../../..' . '/lib/public/IPreview.php',
'OCP\\IRequest' => __DIR__ . '/../../..' . '/lib/public/IRequest.php',
'OCP\\IRequestId' => __DIR__ . '/../../..' . '/lib/public/IRequestId.php',
'OCP\\ISearch' => __DIR__ . '/../../..' . '/lib/public/ISearch.php',
'OCP\\IServerContainer' => __DIR__ . '/../../..' . '/lib/public/IServerContainer.php',
'OCP\\ISession' => __DIR__ . '/../../..' . '/lib/public/ISession.php',
'OCP\\IStreamImage' => __DIR__ . '/../../..' . '/lib/public/IStreamImage.php',
@ -1298,7 +1297,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Controller\\RecommendedAppsController' => __DIR__ . '/../../..' . '/core/Controller/RecommendedAppsController.php',
'OC\\Core\\Controller\\ReferenceApiController' => __DIR__ . '/../../..' . '/core/Controller/ReferenceApiController.php',
'OC\\Core\\Controller\\ReferenceController' => __DIR__ . '/../../..' . '/core/Controller/ReferenceController.php',
'OC\\Core\\Controller\\SearchController' => __DIR__ . '/../../..' . '/core/Controller/SearchController.php',
'OC\\Core\\Controller\\SetupController' => __DIR__ . '/../../..' . '/core/Controller/SetupController.php',
'OC\\Core\\Controller\\TaskProcessingApiController' => __DIR__ . '/../../..' . '/core/Controller/TaskProcessingApiController.php',
'OC\\Core\\Controller\\TeamsApiController' => __DIR__ . '/../../..' . '/core/Controller/TeamsApiController.php',
@ -1846,7 +1844,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Route\\CachingRouter' => __DIR__ . '/../../..' . '/lib/private/Route/CachingRouter.php',
'OC\\Route\\Route' => __DIR__ . '/../../..' . '/lib/private/Route/Route.php',
'OC\\Route\\Router' => __DIR__ . '/../../..' . '/lib/private/Route/Router.php',
'OC\\Search' => __DIR__ . '/../../..' . '/lib/private/Search.php',
'OC\\Search\\FilterCollection' => __DIR__ . '/../../..' . '/lib/private/Search/FilterCollection.php',
'OC\\Search\\FilterFactory' => __DIR__ . '/../../..' . '/lib/private/Search/FilterFactory.php',
'OC\\Search\\Filter\\BooleanFilter' => __DIR__ . '/../../..' . '/lib/private/Search/Filter/BooleanFilter.php',
@ -1857,11 +1854,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Search\\Filter\\StringFilter' => __DIR__ . '/../../..' . '/lib/private/Search/Filter/StringFilter.php',
'OC\\Search\\Filter\\StringsFilter' => __DIR__ . '/../../..' . '/lib/private/Search/Filter/StringsFilter.php',
'OC\\Search\\Filter\\UserFilter' => __DIR__ . '/../../..' . '/lib/private/Search/Filter/UserFilter.php',
'OC\\Search\\Provider\\File' => __DIR__ . '/../../..' . '/lib/private/Search/Provider/File.php',
'OC\\Search\\Result\\Audio' => __DIR__ . '/../../..' . '/lib/private/Search/Result/Audio.php',
'OC\\Search\\Result\\File' => __DIR__ . '/../../..' . '/lib/private/Search/Result/File.php',
'OC\\Search\\Result\\Folder' => __DIR__ . '/../../..' . '/lib/private/Search/Result/Folder.php',
'OC\\Search\\Result\\Image' => __DIR__ . '/../../..' . '/lib/private/Search/Result/Image.php',
'OC\\Search\\SearchComposer' => __DIR__ . '/../../..' . '/lib/private/Search/SearchComposer.php',
'OC\\Search\\SearchQuery' => __DIR__ . '/../../..' . '/lib/private/Search/SearchQuery.php',
'OC\\Search\\UnsupportedFilter' => __DIR__ . '/../../..' . '/lib/private/Search/UnsupportedFilter.php',

@ -1,100 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC;
use OCP\ISearch;
use OCP\Search\PagedProvider;
use OCP\Search\Provider;
use Psr\Log\LoggerInterface;
/**
* Provide an interface to all search providers
*/
class Search implements ISearch {
/** @var Provider[] */
private $providers = [];
private $registeredProviders = [];
/**
* Search all providers for $query
* @param string $query
* @param string[] $inApps optionally limit results to the given apps
* @param int $page pages start at page 1
* @param int $size, 0 = all
* @return array An array of OC\Search\Result's
*/
public function searchPaged($query, array $inApps = [], $page = 1, $size = 30) {
$this->initProviders();
$results = [];
foreach ($this->providers as $provider) {
if (! $provider->providesResultsFor($inApps)) {
continue;
}
if ($provider instanceof PagedProvider) {
$results = array_merge($results, $provider->searchPaged($query, $page, $size));
} elseif ($provider instanceof Provider) {
$providerResults = $provider->search($query);
if ($size > 0) {
$slicedResults = array_slice($providerResults, ($page - 1) * $size, $size);
$results = array_merge($results, $slicedResults);
} else {
$results = array_merge($results, $providerResults);
}
} else {
\OCP\Server::get(LoggerInterface::class)->warning('Ignoring Unknown search provider', ['provider' => $provider]);
}
}
return $results;
}
/**
* Remove all registered search providers
*/
public function clearProviders() {
$this->providers = [];
$this->registeredProviders = [];
}
/**
* Remove one existing search provider
* @param string $provider class name of a OC\Search\Provider
*/
public function removeProvider($provider) {
$this->registeredProviders = array_filter(
$this->registeredProviders,
function ($element) use ($provider) {
return ($element['class'] != $provider);
}
);
// force regeneration of providers on next search
$this->providers = [];
}
/**
* Register a new search provider to search with
* @param string $class class name of a OC\Search\Provider
* @param array $options optional
*/
public function registerProvider($class, array $options = []) {
$this->registeredProviders[] = ['class' => $class, 'options' => $options];
}
/**
* Create instances of all the registered search providers
*/
private function initProviders() {
if (! empty($this->providers)) {
return;
}
foreach ($this->registeredProviders as $provider) {
$class = $provider['class'];
$options = $provider['options'];
$this->providers[] = new $class($options);
}
}
}

@ -1,87 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Search\Provider;
use OC\Files\Search\SearchComparison;
use OC\Files\Search\SearchOrder;
use OC\Files\Search\SearchQuery;
use OCP\Files\FileInfo;
use OCP\Files\IRootFolder;
use OCP\Files\Search\ISearchComparison;
use OCP\Files\Search\ISearchOrder;
use OCP\IUserSession;
use OCP\Search\PagedProvider;
/**
* Provide search results from the 'files' app
* @deprecated 20.0.0
*/
class File extends PagedProvider {
/**
* Search for files and folders matching the given query
*
* @param string $query
* @param int|null $limit
* @param int|null $offset
* @return \OCP\Search\Result[]
* @deprecated 20.0.0
*/
public function search($query, ?int $limit = null, ?int $offset = null) {
/** @var IRootFolder $rootFolder */
$rootFolder = \OCP\Server::get(IRootFolder::class);
/** @var IUserSession $userSession */
$userSession = \OCP\Server::get(IUserSession::class);
$user = $userSession->getUser();
if (!$user) {
return [];
}
$userFolder = $rootFolder->getUserFolder($user->getUID());
$fileQuery = new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', '%' . $query . '%'),
(int)$limit,
(int)$offset,
[
new SearchOrder(ISearchOrder::DIRECTION_DESCENDING, 'mtime'),
],
$user
);
$files = $userFolder->search($fileQuery);
$results = [];
// edit results
foreach ($files as $fileData) {
// create audio result
if ($fileData->getMimePart() === 'audio') {
$result = new \OC\Search\Result\Audio($fileData);
}
// create image result
elseif ($fileData->getMimePart() === 'image') {
$result = new \OC\Search\Result\Image($fileData);
}
// create folder result
elseif ($fileData->getMimetype() === FileInfo::MIMETYPE_FOLDER) {
$result = new \OC\Search\Result\Folder($fileData);
}
// or create file result
else {
$result = new \OC\Search\Result\File($fileData);
}
// add to results
$results[] = $result;
}
// return
return $results;
}
public function searchPaged($query, $page, $size) {
if ($size === 0) {
return $this->search($query);
} else {
return $this->search($query, $size, ($page - 1) * $size);
}
}
}

@ -1,25 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Search\Result;
/**
* A found audio file
* @deprecated 20.0.0
*/
class Audio extends File {
/**
* Type name; translated in templates
* @var string
* @deprecated 20.0.0
*/
public $type = 'audio';
/**
* @TODO add ID3 information
*/
}

@ -1,132 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Search\Result;
use OCP\Files\FileInfo;
use OCP\Files\Folder;
use OCP\IPreview;
use OCP\IUserSession;
/**
* A found file
* @deprecated 20.0.0
*/
class File extends \OCP\Search\Result {
/**
* Type name; translated in templates
* @var string
* @deprecated 20.0.0
*/
public $type = 'file';
/**
* Path to file
* @var string
* @deprecated 20.0.0
*/
public $path;
/**
* Size, in bytes
* @var int
* @deprecated 20.0.0
*/
public $size;
/**
* Date modified, in human readable form
* @var string
* @deprecated 20.0.0
*/
public $modified;
/**
* File mime type
* @var string
* @deprecated 20.0.0
*/
public $mime_type;
/**
* File permissions:
*
* @var string
* @deprecated 20.0.0
*/
public $permissions;
/**
* Has a preview
*
* @var string
* @deprecated 20.0.0
*/
public $has_preview;
/**
* Create a new file search result
* @param FileInfo $data file data given by provider
* @deprecated 20.0.0
*/
public function __construct(FileInfo $data) {
$path = $this->getRelativePath($data->getPath());
$this->id = $data->getId();
$this->name = $data->getName();
$this->link = \OC::$server->getURLGenerator()->linkToRoute(
'files.view.index',
[
'dir' => dirname($path),
'scrollto' => $data->getName(),
]
);
$this->permissions = $data->getPermissions();
$this->path = $path;
$this->size = $data->getSize();
$this->modified = $data->getMtime();
$this->mime_type = $data->getMimetype();
$this->has_preview = $this->hasPreview($data);
}
/**
* @var Folder $userFolderCache
* @deprecated 20.0.0
*/
protected static $userFolderCache = null;
/**
* converts a path relative to the users files folder
* eg /user/files/foo.txt -> /foo.txt
* @param string $path
* @return string relative path
* @deprecated 20.0.0
*/
protected function getRelativePath($path) {
if (!isset(self::$userFolderCache)) {
$userSession = \OC::$server->get(IUserSession::class);
$userID = $userSession->getUser()->getUID();
self::$userFolderCache = \OC::$server->getUserFolder($userID);
}
$relativePath = self::$userFolderCache->getRelativePath($path);
if ($relativePath === null) {
throw new \Exception("Search result not in user folder");
}
return $relativePath;
}
/**
* Is the preview available
* @param FileInfo $data
* @return bool
* @deprecated 20.0.0
*/
protected function hasPreview($data) {
$previewManager = \OC::$server->get(IPreview::class);
return $previewManager->isAvailable($data);
}
}

@ -1,21 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Search\Result;
/**
* A found folder
* @deprecated 20.0.0
*/
class Folder extends File {
/**
* Type name; translated in templates
* @var string
* @deprecated 20.0.0
*/
public $type = 'folder';
}

@ -1,25 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OC\Search\Result;
/**
* A found image file
* @deprecated 20.0.0
*/
class Image extends File {
/**
* Type name; translated in templates
* @var string
* @deprecated 20.0.0
*/
public $type = 'image';
/**
* @TODO add EXIF information
*/
}

@ -185,7 +185,6 @@ use OCP\IPhoneNumberUtil;
use OCP\IPreview;
use OCP\IRequest;
use OCP\IRequestId;
use OCP\ISearch;
use OCP\IServerContainer;
use OCP\ISession;
use OCP\ITagManager;
@ -765,10 +764,6 @@ class Server extends ServerContainer implements IServerContainer {
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('Router', IRouter::class);
$this->registerAlias(ISearch::class, Search::class);
/** @deprecated 19.0.0 */
$this->registerDeprecatedAlias('Search', ISearch::class);
$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
$config = $c->get(\OCP\IConfig::class);
if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === \OC\Memcache\Redis::class) {
@ -1809,16 +1804,6 @@ class Server extends ServerContainer implements IServerContainer {
return $this->get(IRouter::class);
}
/**
* Returns a search instance
*
* @return ISearch
* @deprecated 20.0.0
*/
public function getSearch() {
return $this->get(ISearch::class);
}
/**
* Returns a SecureRandom instance
*

@ -1,51 +0,0 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCP;
/**
* Small Interface for Search
* @since 7.0.0
* @deprecated 20.0.0
*/
interface ISearch {
/**
* Search all providers for $query
* @param string $query
* @param string[] $inApps optionally limit results to the given apps
* @param int $page pages start at page 1
* @param int $size
* @return array An array of OCP\Search\Result's
* @since 8.0.0
* @deprecated 20.0.0
*/
public function searchPaged($query, array $inApps = [], $page = 1, $size = 30);
/**
* Register a new search provider to search with
* @param string $class class name of a OCP\Search\Provider
* @param array $options optional
* @since 7.0.0
* @deprecated 20.0.0
*/
public function registerProvider($class, array $options = []);
/**
* Remove one existing search provider
* @param string $provider class name of a OCP\Search\Provider
* @since 7.0.0
* @deprecated 20.0.0
*/
public function removeProvider($provider);
/**
* Remove all registered search providers
* @since 7.0.0
* @deprecated 20.0.0
*/
public function clearProviders();
}

@ -343,15 +343,6 @@ interface IServerContainer extends ContainerInterface, IContainer {
*/
public function getRouter();
/**
* Returns a search instance
*
* @return \OCP\ISearch
* @since 7.0.0
* @deprecated 20.0.0
*/
public function getSearch();
/**
* Get the certificate manager
*

@ -119,8 +119,6 @@ class ServerTest extends \Test\TestCase {
['RootFolder', '\OCP\Files\Folder'],
['Router', '\OCP\Route\IRouter'],
['Search', '\OC\Search'],
['Search', '\OCP\ISearch'],
['SecureRandom', '\OC\Security\SecureRandom'],
['SecureRandom', '\OCP\Security\ISecureRandom'],
['ShareManager', '\OC\Share20\Manager'],