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

This commit is contained in:
Vishnu Mohandas 2024-01-24 09:54:28 +05:30 committed by GitHub
commit 26ddf3aed1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 27 deletions

View file

@ -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 = [];

View file

@ -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;
}

View file

@ -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);

View file

@ -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"