diff --git a/mobile/lib/services/search_service.dart b/mobile/lib/services/search_service.dart index 8e29b9fc21..20c29119be 100644 --- a/mobile/lib/services/search_service.dart +++ b/mobile/lib/services/search_service.dart @@ -86,10 +86,6 @@ class SearchService { }); } - Set ignoreCollections() { - return CollectionsService.instance.getHiddenCollectionIds(); - } - Future> getAllFilesForSearch() async { if (_cachedFilesFuture != null && _cachedFilesForSearch != null) { return _cachedFilesForSearch!; @@ -220,7 +216,7 @@ class SearchService { for (var yearData in YearsData.instance.yearsData) { if (yearData.year.startsWith(yearFromQuery)) { final List filesInYear = - await _getFilesInYear(yearData.duration); + await _getFilesWithDuration([yearData.duration]); if (filesInYear.isNotEmpty) { searchResults.add( GenericSearchResult( @@ -282,7 +278,7 @@ class SearchService { Future getRadomYearSearchResult() async { for (var yearData in YearsData.instance.yearsData..shuffle()) { final List filesInYear = - await _getFilesInYear(yearData.duration); + await _getFilesWithDuration([yearData.duration]); if (filesInYear.isNotEmpty) { return GenericSearchResult( ResultType.year, @@ -308,11 +304,8 @@ class SearchService { ) async { final List searchResults = []; for (var month in _getMatchingMonths(context, query)) { - final matchedFiles = - await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( _getDurationsOfMonthInEveryYear(month.monthNumber), - ignoreCollections(), - order: 'DESC', ); if (matchedFiles.isNotEmpty) { searchResults.add( @@ -339,11 +332,8 @@ class SearchService { ) async { final months = getMonthData(context)..shuffle(); for (MonthData month in months) { - final matchedFiles = - await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( _getDurationsOfMonthInEveryYear(month.monthNumber), - ignoreCollections(), - order: 'DESC', ); if (matchedFiles.isNotEmpty) { return GenericSearchResult( @@ -375,11 +365,8 @@ class SearchService { for (var holiday in holidays) { if (holiday.name.toLowerCase().contains(query.toLowerCase())) { - final matchedFiles = - await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( _getDurationsForCalendarDateInEveryYear(holiday.day, holiday.month), - ignoreCollections(), - order: 'DESC', ); if (matchedFiles.isNotEmpty) { searchResults.add( @@ -407,11 +394,8 @@ class SearchService { ) async { final holidays = getHolidays(context)..shuffle(); for (var holiday in holidays) { - final matchedFiles = - await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( _getDurationsForCalendarDateInEveryYear(holiday.day, holiday.month), - ignoreCollections(), - order: 'DESC', ); if (matchedFiles.isNotEmpty) { return GenericSearchResult( @@ -1163,11 +1147,8 @@ class SearchService { final int day = potentialDate.item1; final int month = potentialDate.item2.monthNumber; final int? year = potentialDate.item3; // nullable - final matchedFiles = - await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( _getDurationsForCalendarDateInEveryYear(day, month, year: year), - ignoreCollections(), - order: 'DESC', ); if (matchedFiles.isNotEmpty) { final name = '$day ${potentialDate.item2.name} ${year ?? ''}'; @@ -1347,10 +1328,8 @@ class SearchService { endOfDay.microsecondsSinceEpoch, ]; - final matchedFiles = await remoteCache.getFilesCreatedWithinDurations( + final matchedFiles = await _getFilesWithDuration( [durationOfDay], - ignoreCollections(), - order: 'DESC', ); final name = DateFormat.yMMMd(Localizations.localeOf(context).languageCode) @@ -1563,10 +1542,12 @@ class SearchService { .toList(); } - Future> _getFilesInYear(List durationOfYear) async { + Future> _getFilesWithDuration( + List> durations, + ) async { return await remoteCache.getFilesCreatedWithinDurations( - [durationOfYear], - ignoreCollections(), + durations, + CollectionsService.instance.getHiddenCollectionIds(), order: "DESC", ); }