Преглед на файлове

Merge cities and location tags, prioritizing the former (#1674)

Vishnu Mohandas преди 1 година
родител
ревизия
26ddf3aed1
променени са 4 файла, в които са добавени 19 реда и са изтрити 27 реда
  1. 1 1
      lib/services/location_service.dart
  2. 17 17
      lib/services/search_service.dart
  3. 0 8
      lib/ui/viewer/search/search_widget.dart
  4. 1 1
      pubspec.yaml

+ 1 - 1
lib/services/location_service.dart

@@ -26,7 +26,7 @@ class LocationService {
 
   static final LocationService instance = LocationService._privateConstructor();
 
-  static const kCitiesRemotePath = "https://assets.ente.io/world_cities.json";
+  static const kCitiesRemotePath = "https://static.ente.io/world_cities.json";
 
   List<City> _cities = [];
 

+ 17 - 17
lib/services/search_service.dart

@@ -595,9 +595,7 @@ class SearchService {
     return searchResults;
   }
 
-  Future<List<GenericSearchResult>> getLocationResults(
-    String query,
-  ) async {
+  Future<List<GenericSearchResult>> getLocationResults(String query) async {
     final locationTagEntities =
         (await LocationService.instance.getLocationTags());
     final Map<LocalEntity<LocationTag>, List<EnteFile>> result = {};
@@ -657,13 +655,16 @@ class SearchService {
         );
       }
     }
+    final locationTagNames = <String>{};
     for (MapEntry<LocalEntity<LocationTag>, List<EnteFile>> entry
         in result.entries) {
       if (entry.value.isNotEmpty) {
+        final name = entry.key.item.name;
+        locationTagNames.add(name);
         searchResults.add(
           GenericSearchResult(
             ResultType.location,
-            entry.key.item.name,
+            name,
             entry.value,
             onResultTap: (ctx) {
               routeToPage(
@@ -678,21 +679,20 @@ class SearchService {
         );
       }
     }
-    return searchResults;
-  }
 
-  Future<List<GenericSearchResult>> getCityResults(String query) async {
-    final files = await getAllFiles();
-    final results = await LocationService.instance.getFilesInCity(files, query);
-    final List<GenericSearchResult> searchResults = [];
+    final results =
+        await LocationService.instance.getFilesInCity(allFiles, query);
     for (final entry in results.entries) {
-      searchResults.add(
-        GenericSearchResult(
-          ResultType.location,
-          entry.key.city,
-          entry.value,
-        ),
-      );
+      // If the location tag already exists for a city, don't add it again
+      if (!locationTagNames.contains(entry.key.city)) {
+        searchResults.add(
+          GenericSearchResult(
+            ResultType.location,
+            entry.key.city,
+            entry.value,
+          ),
+        );
+      }
     }
     return searchResults;
   }

+ 0 - 8
lib/ui/viewer/search/search_widget.dart

@@ -2,7 +2,6 @@ import "dart:async";
 
 import "package:flutter/material.dart";
 import "package:flutter/scheduler.dart";
-import "package:logging/logging.dart";
 import "package:photos/core/event_bus.dart";
 import "package:photos/events/clear_and_unfocus_search_bar_event.dart";
 import "package:photos/events/tab_changed_event.dart";
@@ -33,7 +32,6 @@ class SearchWidgetState extends State<SearchWidget> {
   static final isLoading = ValueNotifier(false);
   final _searchService = SearchService.instance;
   final _debouncer = Debouncer(const Duration(milliseconds: 200));
-  final Logger _logger = Logger((SearchWidgetState).toString());
   late FocusNode focusNode;
   StreamSubscription<TabDoubleTapEvent>? _tabDoubleTapEvent;
   double _bottomPadding = 0.0;
@@ -256,12 +254,6 @@ class SearchWidgetState extends State<SearchWidget> {
       },
     );
 
-    _searchService.getCityResults(query).then(
-      (results) {
-        onResultsReceived(results);
-      },
-    );
-
     _searchService.getCollectionSearchResults(query).then(
       (collectionResults) {
         onResultsReceived(collectionResults);

+ 1 - 1
pubspec.yaml

@@ -12,7 +12,7 @@ description: ente photos application
 # Read more about iOS versioning at
 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
 
-version: 0.8.45+565
+version: 0.8.46+566
 
 environment:
   sdk: ">=3.0.0 <4.0.0"