mirror of
https://github.com/nextcloud/server.git
synced 2026-06-13 10:40:40 -04:00
feat(file-search): add property to SearchQuery and check select fields to decide wheter to join extended cache
Signed-off-by: Cristian Scheid <cristianscheid@gmail.com>
This commit is contained in:
parent
73cd2bf2ae
commit
32c79b4f6a
4 changed files with 34 additions and 6 deletions
|
|
@ -347,6 +347,15 @@ class FileSearchBackend implements ISearchBackend {
|
|||
}
|
||||
}, $query->orderBy);
|
||||
|
||||
$selectFields = [];
|
||||
foreach ($query->select as $searchProperty) {
|
||||
try {
|
||||
$selectFields[] = $this->mapPropertyNameToColumn($searchProperty);
|
||||
} catch (\InvalidArgumentException) {
|
||||
// property does not represent a column on DB
|
||||
}
|
||||
}
|
||||
|
||||
$limit = $query->limit;
|
||||
$maxResults = $limit->maxResults !== 0 ? (int)$limit->maxResults : 100;
|
||||
$offset = $limit->firstResult;
|
||||
|
|
@ -380,7 +389,8 @@ class FileSearchBackend implements ISearchBackend {
|
|||
$offset,
|
||||
$orders,
|
||||
$this->user,
|
||||
$limitHome
|
||||
$limitHome,
|
||||
$selectFields
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -151,13 +151,16 @@ class QuerySearchHelper {
|
|||
|
||||
$builder = $this->getQueryBuilder();
|
||||
|
||||
$requestedFields = $this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation());
|
||||
$requestedFields = array_merge(
|
||||
$this->searchBuilder->extractRequestedFields($searchQuery->getSearchOperation()),
|
||||
array_map(fn ($order) => $order->getField(), $searchQuery->getOrder()),
|
||||
$searchQuery->getSelectFields(),
|
||||
);
|
||||
|
||||
$orderFields = array_map(fn ($order) => $order->getField(), $searchQuery->getOrder());
|
||||
|
||||
$joinExtendedCache = in_array('creation_time', $requestedFields)
|
||||
$joinExtendedCache = in_array('metadata_etag', $requestedFields)
|
||||
|| in_array('creation_time', $requestedFields)
|
||||
|| in_array('upload_time', $requestedFields)
|
||||
|| in_array('last_activity', $orderFields);
|
||||
|| in_array('last_activity', $requestedFields);
|
||||
|
||||
$query = $builder->selectFileCache('file', $joinExtendedCache);
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use OCP\IUser;
|
|||
class SearchQuery implements ISearchQuery {
|
||||
/**
|
||||
* @param ISearchOrder[] $order
|
||||
* @param list<string> $selectFields
|
||||
*/
|
||||
public function __construct(
|
||||
private ISearchOperator $searchOperation,
|
||||
|
|
@ -24,6 +25,7 @@ class SearchQuery implements ISearchQuery {
|
|||
private array $order,
|
||||
private ?IUser $user = null,
|
||||
private bool $limitToHome = false,
|
||||
private array $selectFields = [],
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -59,4 +61,9 @@ class SearchQuery implements ISearchQuery {
|
|||
public function limitToHome(): bool {
|
||||
return $this->limitToHome;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function getSelectFields(): array {
|
||||
return $this->selectFields;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,4 +57,12 @@ interface ISearchQuery {
|
|||
* @since 18.0.0
|
||||
*/
|
||||
public function limitToHome(): bool;
|
||||
|
||||
/**
|
||||
* The fields to include in the search results
|
||||
*
|
||||
* @return list<string>
|
||||
* @since 34.0.1
|
||||
*/
|
||||
public function getSelectFields(): array;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue