Merge pull request #45950 from nextcloud/chore/remove-depreacted-search
chore: Remove deprecated legacy search backendpull/46918/head
commit
014fcb0131
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
*/
|
||||
}
|
||||
@ -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();
|
||||
}
|
||||
Loading…
Reference in New Issue