mirror of
https://github.com/immich-app/immich.git
synced 2026-03-22 14:19:26 +03:00
Smart search currently returns a list of assets by their score. It would be nice if we could instead filter assets, and then list them by date. This is the default behaviour of other platforms.
81 lines
3.1 KiB
Dart
81 lines
3.1 KiB
Dart
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart' hide AssetVisibility;
|
|
import 'package:immich_mobile/infrastructure/repositories/api.repository.dart';
|
|
import 'package:immich_mobile/models/search/search_filter.model.dart';
|
|
import 'package:openapi/api.dart';
|
|
|
|
class SearchApiRepository extends ApiRepository {
|
|
final SearchApi _api;
|
|
|
|
const SearchApiRepository(this._api);
|
|
|
|
Future<SearchResponseDto?> search(SearchFilter filter, int page) {
|
|
AssetTypeEnum? type;
|
|
if (filter.mediaType.index == AssetType.image.index) {
|
|
type = AssetTypeEnum.IMAGE;
|
|
} else if (filter.mediaType.index == AssetType.video.index) {
|
|
type = AssetTypeEnum.VIDEO;
|
|
}
|
|
|
|
if ((filter.context != null && filter.context!.isNotEmpty) ||
|
|
(filter.assetId != null && filter.assetId!.isNotEmpty)) {
|
|
return _api.searchSmart(
|
|
SmartSearchDto(
|
|
query: filter.context,
|
|
queryAssetId: filter.assetId,
|
|
language: filter.language,
|
|
country: filter.location.country,
|
|
state: filter.location.state,
|
|
city: filter.location.city,
|
|
make: filter.camera.make,
|
|
model: filter.camera.model,
|
|
takenAfter: filter.date.takenAfter,
|
|
takenBefore: filter.date.takenBefore,
|
|
visibility: filter.display.isArchive ? AssetVisibility.archive : AssetVisibility.timeline,
|
|
rating: filter.rating.rating,
|
|
isFavorite: filter.display.isFavorite ? true : null,
|
|
isNotInAlbum: filter.display.isNotInAlbum ? true : null,
|
|
personIds: filter.people.map((e) => e.id).toList(),
|
|
tagIds: filter.tagIds,
|
|
type: type,
|
|
order: filter.order,
|
|
page: page,
|
|
size: 100,
|
|
),
|
|
);
|
|
}
|
|
|
|
return _api.searchAssets(
|
|
MetadataSearchDto(
|
|
originalFileName: filter.filename != null && filter.filename!.isNotEmpty ? filter.filename : null,
|
|
country: filter.location.country,
|
|
description: filter.description != null && filter.description!.isNotEmpty ? filter.description : null,
|
|
ocr: filter.ocr != null && filter.ocr!.isNotEmpty ? filter.ocr : null,
|
|
state: filter.location.state,
|
|
city: filter.location.city,
|
|
make: filter.camera.make,
|
|
model: filter.camera.model,
|
|
takenAfter: filter.date.takenAfter,
|
|
takenBefore: filter.date.takenBefore,
|
|
visibility: filter.display.isArchive ? AssetVisibility.archive : AssetVisibility.timeline,
|
|
rating: filter.rating.rating,
|
|
isFavorite: filter.display.isFavorite ? true : null,
|
|
isNotInAlbum: filter.display.isNotInAlbum ? true : null,
|
|
personIds: filter.people.map((e) => e.id).toList(),
|
|
tagIds: filter.tagIds,
|
|
type: type,
|
|
order: filter.order ?? AssetOrder.desc,
|
|
page: page,
|
|
size: 1000,
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<List<String>?> getSearchSuggestions(
|
|
SearchSuggestionType type, {
|
|
String? country,
|
|
String? state,
|
|
String? make,
|
|
String? model,
|
|
}) => _api.getSearchSuggestions(type, country: country, state: state, make: make, model: model);
|
|
}
|