Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

add functionality to limit the number of search results returned from description search. Randomized the results from a decent pool of results too

ashilkn9d31007fc733
diff --git a/lib/services/search_service.dart b/lib/services/search_service.dart
index b15e2c3056..c50b3945c1 100644
--- a/lib/services/search_service.dart
+++ b/lib/services/search_service.dart
@@ -256,9 +256,19 @@ class SearchService {
//string.contains().
final orderedSubDescriptions = <Map<int, List<String>>>[];
final descriptionAndMatchingFiles = <String, List<EnteFile>>{};
+ int distinctFullDescriptionCount = 0;
for (EnteFile file in allFiles) {
if (file.caption != null && file.caption!.isNotEmpty) {
+ //This limit doesn't necessarily have to be the limit parameter of the
+ //method. Using the same variable to avoid unwanted iterations (this and
+ //nested loops) in case there is a limit passed. Using the limit passed
+ //here so that there will be almost always be more than 7
+ //descriptionAndMatchingFiles and can shuffle and choose only limited
+ //elements from it. Without shuffling, result will be ["hello", "world",
+ //"hello world"] for the string "hello world"
+ if (limit != null && distinctFullDescriptionCount >= limit) break;
+ distinctFullDescriptionCount++;
final words = file.caption!.split(" ");
orderedSubDescriptions.add({0: <String>[], 1: <String>[]});
@@ -306,8 +316,11 @@ class SearchService {
searchResults
.add(GenericSearchResult(ResultType.fileCaption, key, value));
});
-
- return searchResults;
+ if (limit != null && distinctFullDescriptionCount >= limit) {
+ return (searchResults..shuffle()).sublist(0, limit);
+ } else {
+ return searchResults;
+ }
}
Future<List<GenericSearchResult>> getCaptionAndNameResults(