|
@@ -52,20 +52,6 @@ class SearchService {
|
|
return _cachedFilesFuture;
|
|
return _cachedFilesFuture;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<File>> getFileSearchResults(String query) async {
|
|
|
|
- final List<File> fileSearchResults = [];
|
|
|
|
- final List<File> files = await _getAllFiles();
|
|
|
|
- for (var file in files) {
|
|
|
|
- if (fileSearchResults.length >= _maximumResultsLimit) {
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- if (file.title.toLowerCase().contains(query.toLowerCase())) {
|
|
|
|
- fileSearchResults.add(file);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return fileSearchResults;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
void clearCache() {
|
|
void clearCache() {
|
|
_cachedFilesFuture = null;
|
|
_cachedFilesFuture = null;
|
|
}
|
|
}
|
|
@@ -208,7 +194,7 @@ class SearchService {
|
|
return searchResults;
|
|
return searchResults;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<GenericSearchResult>> getCaptionResults(
|
|
|
|
|
|
+ Future<List<GenericSearchResult>> getCaptionAndNameResults(
|
|
String query,
|
|
String query,
|
|
) async {
|
|
) async {
|
|
final List<GenericSearchResult> searchResults = [];
|
|
final List<GenericSearchResult> searchResults = [];
|
|
@@ -217,15 +203,31 @@ class SearchService {
|
|
}
|
|
}
|
|
final RegExp pattern = RegExp(query, caseSensitive: false);
|
|
final RegExp pattern = RegExp(query, caseSensitive: false);
|
|
final List<File> allFiles = await _getAllFiles();
|
|
final List<File> allFiles = await _getAllFiles();
|
|
- final matchedFiles = allFiles
|
|
|
|
- .where((e) => e.caption != null && pattern.hasMatch(e.caption))
|
|
|
|
- .toList();
|
|
|
|
- if (matchedFiles.isNotEmpty) {
|
|
|
|
|
|
+ final List<File> captionMatch = <File>[];
|
|
|
|
+ final List<File> displayNameMatch = <File>[];
|
|
|
|
+ for (File eachFile in allFiles) {
|
|
|
|
+ if (eachFile.caption != null && pattern.hasMatch(eachFile.caption)) {
|
|
|
|
+ captionMatch.add(eachFile);
|
|
|
|
+ }
|
|
|
|
+ if (pattern.hasMatch(eachFile.displayName)) {
|
|
|
|
+ displayNameMatch.add(eachFile);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (captionMatch.isNotEmpty) {
|
|
searchResults.add(
|
|
searchResults.add(
|
|
GenericSearchResult(
|
|
GenericSearchResult(
|
|
ResultType.fileCaption,
|
|
ResultType.fileCaption,
|
|
query,
|
|
query,
|
|
- matchedFiles,
|
|
|
|
|
|
+ captionMatch,
|
|
|
|
+ ),
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+ if (displayNameMatch.isNotEmpty) {
|
|
|
|
+ searchResults.add(
|
|
|
|
+ GenericSearchResult(
|
|
|
|
+ ResultType.file,
|
|
|
|
+ query,
|
|
|
|
+ displayNameMatch,
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|