Skip to content

Commit

Permalink
fix: adopt search to NC 28 filters
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Molenaar <[email protected]>
  • Loading branch information
SMillerDev committed Nov 15, 2023
1 parent 99e90ac commit 412ce77
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
### Changed

### Fixed
- Fix search support for Nextcloud 28

# Releases
## [25.0.0-alpha2] - 2023-11-08
Expand Down
7 changes: 6 additions & 1 deletion lib/Search/FeedSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ public function getOrder(string $route, array $routeParameters): int
public function search(IUser $user, ISearchQuery $query): SearchResult
{
$list = [];
$term = strtolower($query->getTerm());
if (method_exists($query, 'getFilter')) {
$term = $query->getFilter('term')?->get() ?? '';
} else {
$term = $query->getTerm();

Check failure on line 65 in lib/Search/FeedSearchProvider.php

View workflow job for this annotation

GitHub Actions / phpstan: Nextcloud pre-release with 8.2

Call to deprecated method getTerm() of class OCP\Search\ISearchQuery: 28.0.0
}
$term = strtolower($term);

foreach ($this->service->findAllForUser($user->getUID()) as $feed) {
if (strpos(strtolower($feed->getTitle()), $term) === false) {
Expand Down
7 changes: 6 additions & 1 deletion lib/Search/FolderSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ public function getOrder(string $route, array $routeParameters): int
public function search(IUser $user, ISearchQuery $query): SearchResult
{
$list = [];
$term = strtolower($query->getTerm());
if (method_exists($query, 'getFilter')) {
$term = $query->getFilter('term')?->get() ?? '';
} else {
$term = $query->getTerm();

Check failure on line 66 in lib/Search/FolderSearchProvider.php

View workflow job for this annotation

GitHub Actions / phpstan: Nextcloud pre-release with 8.2

Call to deprecated method getTerm() of class OCP\Search\ISearchQuery: 28.0.0
}
$term = strtolower($term);

foreach ($this->service->findAllForUser($user->getUID()) as $folder) {
if (strpos(strtolower($folder->getName()), $term) === false) {
Expand Down
12 changes: 9 additions & 3 deletions lib/Search/ItemSearchProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public function getOrder(string $route, array $routeParameters): int
private function stripTruncate(string $string, int $length = 50): string
{
$string = strip_tags(trim($string));

if (strlen($string) > $length) {
$string = wordwrap($string, $length);
$string = explode("\n", $string, 2);
$string = $string[0];
}

return $string;
}

Expand All @@ -76,13 +76,19 @@ public function search(IUser $user, ISearchQuery $query): SearchResult
$offset = (int) ($query->getCursor() ?? 0);
$limit = $query->getLimit();

if (method_exists($query, 'getFilter')) {
$term = $query->getFilter('term')?->get() ?? '';
} else {
$term = $query->getTerm();

Check failure on line 82 in lib/Search/ItemSearchProvider.php

View workflow job for this annotation

GitHub Actions / phpstan: Nextcloud pre-release with 8.2

Call to deprecated method getTerm() of class OCP\Search\ISearchQuery: 28.0.0
}

$search_result = $this->service->findAllWithFilters(
$user->getUID(),
ListType::ALL_ITEMS,
$limit,
$offset,
false,
[$query->getTerm()]
[$term]
);

$last = end($search_result);
Expand Down

0 comments on commit 412ce77

Please sign in to comment.