Browse Source

Show all cities result for __city query

Neeraj Gupta 1 year ago
parent
commit
e70aef0a68
1 changed files with 12 additions and 5 deletions
  1. 12 5
      lib/services/search_service.dart

+ 12 - 5
lib/services/search_service.dart

@@ -676,17 +676,24 @@ class SearchService {
         );
         );
       }
       }
     }
     }
-
+    //todo: remove this later, this hack is for interval+external evaluation
+    // for suggestions
+    final allCitiesSearch = query == '__city';
+    if (allCitiesSearch) {
+      query = '';
+    }
     final results =
     final results =
         await LocationService.instance.getFilesInCity(allFiles, query);
         await LocationService.instance.getFilesInCity(allFiles, query);
-    for (final entry in results.entries) {
+    final List<City> sortedByResultCount = results.keys.toList()
+      ..sort((a, b) => results[b]!.length.compareTo(results[a]!.length));
+    for (final city in sortedByResultCount) {
       // If the location tag already exists for a city, don't add it again
       // If the location tag already exists for a city, don't add it again
-      if (!locationTagNames.contains(entry.key.city)) {
+      if (!locationTagNames.contains(city.city)) {
         searchResults.add(
         searchResults.add(
           GenericSearchResult(
           GenericSearchResult(
             ResultType.location,
             ResultType.location,
-            entry.key.city,
-            entry.value,
+            city.city,
+            results[city]!,
           ),
           ),
         );
         );
       }
       }