Support for surfacing all matching cities (#1718)

This commit is contained in:
Neeraj Gupta 2024-02-15 12:20:50 +05:30 committed by GitHub
commit 6085aff3e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 5 deletions

View file

@ -7,6 +7,7 @@ import "package:logging/logging.dart";
import "package:photos/core/constants.dart";
import "package:photos/core/event_bus.dart";
import "package:photos/events/location_tag_updated_event.dart";
import "package:photos/extensions/stop_watch.dart";
import "package:photos/models/api/entity/type.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/local_entity_data.dart";
@ -45,6 +46,8 @@ class LocationService {
List<EnteFile> allFiles,
String query,
) async {
final EnteWatch w = EnteWatch("cities_search")..start();
w.log('start for files ${allFiles.length} and query $query');
final result = await _computer.compute(
getCityResults,
param: {
@ -53,6 +56,10 @@ class LocationService {
"files": allFiles,
},
);
w.log(
'end for query: $query on ${allFiles.length} files, found '
'${result.length} cities',
);
return result;
}

View file

@ -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 =
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 (!locationTagNames.contains(entry.key.city)) {
if (!locationTagNames.contains(city.city)) {
searchResults.add(
GenericSearchResult(
ResultType.location,
entry.key.city,
entry.value,
city.city,
results[city]!,
),
);
}