Skip to content

Commit 4ac6c14

Browse files
committed
feat: unified search
Signed-off-by: Crisciany Souza <[email protected]>
1 parent 157afc9 commit 4ac6c14

2 files changed

Lines changed: 26 additions & 38 deletions

File tree

lib/Db/SignRequestMapper.php

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -460,19 +460,20 @@ public function getFilesAssociatedFilesWithMe(
460460
];
461461
}
462462

463-
public function getFilesToSearchProvider(IUser $user, string $term, int $limit, int $offset): array {
463+
public function getFilesToSearchProvider(IUser $user, string $fileName, int $limit, int $offset): array {
464464
$filter = [
465465
'page' => ($offset / $limit) + 1,
466466
'length' => $limit,
467+
'fileName' => $fileName,
467468
];
468469

469-
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($user->getUID(), $filter);
470+
$sort = [
471+
'sortBy' => 'created_at',
472+
'sortDirection' => 'desc',
473+
];
474+
475+
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($user->getUID(), $filter, false, $sort);
470476

471-
if (!empty($term)) {
472-
$qb->andWhere(
473-
$qb->expr()->like('f.name', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($term) . '%'))
474-
);
475-
}
476477

477478
$qb->orderBy('f.created_at', 'DESC');
478479

@@ -481,16 +482,7 @@ public function getFilesToSearchProvider(IUser $user, string $term, int $limit,
481482

482483
while ($row = $result->fetch()) {
483484
try {
484-
$file = new File();
485-
$file->setId((int)$row['id']);
486-
$file->setUserId($row['user_id']);
487-
$file->setNodeId((int)($row['node_id'] ?? 0));
488-
$file->setSignedNodeId($row['signed_node_id'] ? (int)$row['signed_node_id'] : null);
489-
$file->setName($row['name'] ?? '');
490-
$file->setStatus((int)($row['status'] ?? 0));
491-
$file->setUuid($row['uuid'] ?? '');
492-
$file->setCreatedAt($row['created_at'] ?? '');
493-
485+
$file = File::fromRow($row);
494486

495487
$files[] = $file;
496488
} catch (\Exception $e) {
@@ -576,7 +568,7 @@ public function getMyLibresignFile(string $userId, ?array $filter = []): File {
576568
return $file->fromRow($row);
577569
}
578570

579-
private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array $filter = [], bool $count = false): IQueryBuilder {
571+
private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array $filter = [], bool $count = false, array $sort = []): IQueryBuilder {
580572
$qb = $this->db->getQueryBuilder();
581573
$qb->from('libresign_file', 'f')
582574
->leftJoin('f', 'libresign_sign_request', 'sr', 'sr.file_id = f.id')
@@ -687,26 +679,21 @@ private function getFilesAssociatedFilesWithMeQueryBuilder(string $userId, array
687679
$qb->expr()->lte('f.created_at', $qb->createNamedParameter($end, IQueryBuilder::PARAM_STR))
688680
);
689681
}
682+
if (!empty($filter['fileName'])) {
683+
$qb->andWhere(
684+
$qb->expr()->like('f.name', $qb->createNamedParameter('%' . $this->db->escapeLikeParameter($filter['fileName']) . '%'))
685+
);
686+
}
690687
if (!empty($filter['parentFileId'])) {
691688
$qb->andWhere(
692689
$qb->expr()->eq('f.parent_file_id', $qb->createNamedParameter($filter['parentFileId'], IQueryBuilder::PARAM_INT))
693690
);
694691
} else {
695692
$qb->andWhere($qb->expr()->isNull('f.parent_file_id'));
696693
}
697-
} else {
698-
$qb->andWhere($qb->expr()->isNull('f.parent_file_id'));
699694
}
700-
return $qb;
701-
}
702695

703-
private function getFilesAssociatedFilesWithMeStmt(
704-
string $userId,
705-
?array $filter = [],
706-
?array $sort = [],
707-
): Pagination {
708-
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($userId, $filter);
709-
if (!empty($sort['sortBy'])) {
696+
if (!empty($sort['sortBy']) && !empty($sort['sortDirection'])) {
710697
switch ($sort['sortBy']) {
711698
case 'name':
712699
case 'status':
@@ -723,6 +710,16 @@ private function getFilesAssociatedFilesWithMeStmt(
723710
}
724711
}
725712

713+
return $qb;
714+
}
715+
716+
private function getFilesAssociatedFilesWithMeStmt(
717+
string $userId,
718+
?array $filter = [],
719+
?array $sort = [],
720+
): Pagination {
721+
$qb = $this->getFilesAssociatedFilesWithMeQueryBuilder($userId, $filter, false, $sort);
722+
726723
$countQb = $this->getFilesAssociatedFilesWithMeQueryBuilder(
727724
userId: $userId,
728725
filter: $filter,

lib/Search/FileSearchProvider.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use OCP\App\IAppManager;
1616
use OCP\Files\IMimeTypeDetector;
1717
use OCP\Files\IRootFolder;
18-
use OCP\IDBConnection;
1918
use OCP\IL10N;
2019
use OCP\IURLGenerator;
2120
use OCP\IUser;
@@ -30,7 +29,6 @@ public function __construct(
3029
private IURLGenerator $urlGenerator,
3130
private IRootFolder $rootFolder,
3231
private IAppManager $appManager,
33-
private IDBConnection $db,
3432
private IMimeTypeDetector $mimeTypeDetector,
3533
private SignRequestMapper $fileMapper,
3634
) {
@@ -81,13 +79,6 @@ public function search(IUser $user, ISearchQuery $query): SearchResult {
8179
);
8280
}
8381

84-
/**
85-
* Format a File entity as a SearchResultEntry
86-
*
87-
* @param File $file The file entity to format
88-
* @param IUser $user Current user
89-
* @return SearchResultEntry Formatted search result entry
90-
*/
9182
private function formatResult(File $file, IUser $user): SearchResultEntry {
9283
$userFolder = $this->rootFolder->getUserFolder($user->getUID());
9384
$thumbnailUrl = '';

0 commit comments

Comments
 (0)