Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1704,6 +1704,7 @@
"search_by_description_example": "Hiking day in Sapa",
"search_by_filename": "Search by file name or extension",
"search_by_filename_example": "i.e. IMG_1234.JPG or PNG",
"search_camera_lens_model": "Search lens model...",
"search_camera_make": "Search camera make...",
"search_camera_model": "Search camera model...",
"search_city": "Search city...",
Expand Down
13 changes: 10 additions & 3 deletions mobile/openapi/lib/api/search_api.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions mobile/openapi/lib/model/search_suggestion_type.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6410,6 +6410,14 @@
"type": "boolean"
}
},
{
"name": "lensModel",
"required": false,
"in": "query",
"schema": {
"type": "string"
}
},
{
"name": "make",
"required": false,
Expand Down Expand Up @@ -13892,7 +13900,8 @@
"state",
"city",
"camera-make",
"camera-model"
"camera-model",
"camera-lens-model"
],
"type": "string"
},
Expand Down
7 changes: 5 additions & 2 deletions open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3550,9 +3550,10 @@ export function searchAssetStatistics({ statisticsSearchDto }: {
/**
* This endpoint requires the `asset.read` permission.
*/
export function getSearchSuggestions({ country, includeNull, make, model, state, $type }: {
export function getSearchSuggestions({ country, includeNull, lensModel, make, model, state, $type }: {
country?: string;
includeNull?: boolean;
lensModel?: string;
make?: string;
model?: string;
state?: string;
Expand All @@ -3564,6 +3565,7 @@ export function getSearchSuggestions({ country, includeNull, make, model, state,
}>(`/search/suggestions${QS.query(QS.explode({
country,
includeNull,
lensModel,
make,
model,
state,
Expand Down Expand Up @@ -4902,7 +4904,8 @@ export enum SearchSuggestionType {
State = "state",
City = "city",
CameraMake = "camera-make",
CameraModel = "camera-model"
CameraModel = "camera-model",
CameraLensModel = "camera-lens-model"
}
export enum SharedLinkType {
Album = "ALBUM",
Expand Down
5 changes: 5 additions & 0 deletions server/src/dtos/search.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ export enum SearchSuggestionType {
CITY = 'city',
CAMERA_MAKE = 'camera-make',
CAMERA_MODEL = 'camera-model',
CAMERA_LENS_MODEL = 'camera-lens-model',
}

export class SearchSuggestionRequestDto {
Expand All @@ -271,6 +272,10 @@ export class SearchSuggestionRequestDto {
@Optional()
model?: string;

@IsString()
@Optional()
lensModel?: string;

@ValidateBoolean({ optional: true })
@PropertyLifecycle({ addedAt: 'v111.0.0' })
includeNull?: boolean;
Expand Down
12 changes: 12 additions & 0 deletions server/src/queries/search.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,15 @@ where
and "visibility" = $2
and "deletedAt" is null
and "model" is not null

-- SearchRepository.getCameraLensModels
select distinct
on ("lensModel") "lensModel"
from
"asset_exif"
inner join "asset" on "asset"."id" = "asset_exif"."assetId"
where
"ownerId" = any ($1::uuid[])
and "visibility" = $2
and "deletedAt" is null
and "lensModel" is not null
32 changes: 27 additions & 5 deletions server/src/repositories/search.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,17 @@ export interface GetCitiesOptions extends GetStatesOptions {

export interface GetCameraModelsOptions {
make?: string;
lensModel?: string;
}

export interface GetCameraMakesOptions {
model?: string;
lensModel?: string;
}

export interface GetCameraLensModelsOptions {
make?: string;
model?: string;
}

@Injectable()
Expand Down Expand Up @@ -457,25 +464,40 @@ export class SearchRepository {
return res.map((row) => row.city!);
}

@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getCameraMakes(userIds: string[], { model }: GetCameraMakesOptions): Promise<string[]> {
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING, DummyValue.STRING] })
async getCameraMakes(userIds: string[], { model, lensModel }: GetCameraMakesOptions): Promise<string[]> {
const res = await this.getExifField('make', userIds)
.$if(!!model, (qb) => qb.where('model', '=', model!))
.$if(!!lensModel, (qb) => qb.where('lensModel', '=', lensModel!))
.execute();

return res.map((row) => row.make!);
}

@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getCameraModels(userIds: string[], { make }: GetCameraModelsOptions): Promise<string[]> {
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING, DummyValue.STRING] })
async getCameraModels(userIds: string[], { make, lensModel }: GetCameraModelsOptions): Promise<string[]> {
const res = await this.getExifField('model', userIds)
.$if(!!make, (qb) => qb.where('make', '=', make!))
.$if(!!lensModel, (qb) => qb.where('lensModel', '=', lensModel!))
.execute();

return res.map((row) => row.model!);
}

private getExifField<K extends 'city' | 'state' | 'country' | 'make' | 'model'>(field: K, userIds: string[]) {
@GenerateSql({ params: [[DummyValue.UUID], DummyValue.STRING] })
async getCameraLensModels(userIds: string[], { make, model }: GetCameraLensModelsOptions): Promise<string[]> {
const res = await this.getExifField('lensModel', userIds)
.$if(!!make, (qb) => qb.where('make', '=', make!))
.$if(!!model, (qb) => qb.where('model', '=', model!))
.execute();

return res.map((row) => row.lensModel!);
}

private getExifField<K extends 'city' | 'state' | 'country' | 'make' | 'model' | 'lensModel'>(
field: K,
userIds: string[],
) {
return this.db
.selectFrom('asset_exif')
.select(field)
Expand Down
20 changes: 20 additions & 0 deletions server/src/services/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@ describe(SearchService.name, () => {
).resolves.toEqual(['Fujifilm X100VI', null]);
expect(mocks.search.getCameraModels).toHaveBeenCalledWith([authStub.user1.user.id], expect.anything());
});

it('should return search suggestions for camera lens model', async () => {
mocks.search.getCameraLensModels.mockResolvedValue(['10-24mm']);
mocks.partner.getAll.mockResolvedValue([]);

await expect(
sut.getSearchSuggestions(authStub.user1, { includeNull: false, type: SearchSuggestionType.CAMERA_LENS_MODEL }),
).resolves.toEqual(['10-24mm']);
expect(mocks.search.getCameraLensModels).toHaveBeenCalledWith([authStub.user1.user.id], expect.anything());
});

it('should return search suggestions for camera lens model (including null)', async () => {
mocks.search.getCameraLensModels.mockResolvedValue(['10-24mm']);
mocks.partner.getAll.mockResolvedValue([]);

await expect(
sut.getSearchSuggestions(authStub.user1, { includeNull: true, type: SearchSuggestionType.CAMERA_LENS_MODEL }),
).resolves.toEqual(['10-24mm', null]);
expect(mocks.search.getCameraLensModels).toHaveBeenCalledWith([authStub.user1.user.id], expect.anything());
});
});

describe('searchSmart', () => {
Expand Down
3 changes: 3 additions & 0 deletions server/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ export class SearchService extends BaseService {
case SearchSuggestionType.CAMERA_MODEL: {
return this.searchRepository.getCameraModels(userIds, dto);
}
case SearchSuggestionType.CAMERA_LENS_MODEL: {
return this.searchRepository.getCameraLensModels(userIds, dto);
}
default: {
return Promise.resolve([]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
export interface SearchCameraFilter {
make?: string;
model?: string;
lensModel?: string;
}
</script>

<script lang="ts">
import { run } from 'svelte/legacy';

import Combobox, { asComboboxOptions, asSelectedOption } from '$lib/components/shared-components/combobox.svelte';
import { handlePromiseError } from '$lib/utils';
import { SearchSuggestionType, getSearchSuggestions } from '@immich/sdk';
Expand All @@ -21,6 +20,7 @@

let makes: string[] = $state([]);
let models: string[] = $state([]);
let lensModels: string[] = $state([]);

async function updateMakes() {
const results: Array<string | null> = await getSearchSuggestions({
Expand Down Expand Up @@ -48,14 +48,35 @@
filters.model = undefined;
}
}

async function updateLensModels(make?: string, model?: string) {
const results: Array<string | null> = await getSearchSuggestions({
$type: SearchSuggestionType.CameraLensModel,
make,
model,
includeNull: true,
});

lensModels = results.map((result) => result ?? '');

if (filters.lensModel && !lensModels.includes(filters.lensModel)) {
filters.lensModel = undefined;
}
}

let makeFilter = $derived(filters.make);
let modelFilter = $derived(filters.model);
run(() => {
let lensModelFilter = $derived(filters.lensModel);

$effect(() => {
handlePromiseError(updateMakes());
});
run(() => {
$effect(() => {
handlePromiseError(updateModels(makeFilter));
});
$effect(() => {
handlePromiseError(updateLensModels(makeFilter, modelFilter));
});
</script>

<div id="camera-selection">
Expand All @@ -81,5 +102,15 @@
selectedOption={asSelectedOption(modelFilter)}
/>
</div>

<div class="w-full">
<Combobox
label={$t('lens_model')}
onSelect={(option) => (filters.lensModel = option?.value)}
options={asComboboxOptions(lensModels)}
placeholder={$t('search_camera_lens_model')}
selectedOption={asSelectedOption(lensModelFilter)}
/>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions web/src/lib/modals/SearchFilterModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
camera: {
make: withNullAsUndefined(searchQuery.make),
model: withNullAsUndefined(searchQuery.model),
lensModel: withNullAsUndefined(searchQuery.lensModel),
},
date: {
takenAfter: searchQuery.takenAfter ? toStartOfDayDate(searchQuery.takenAfter) : undefined,
Expand Down Expand Up @@ -147,6 +148,7 @@
city: filter.location.city,
make: filter.camera.make,
model: filter.camera.model,
lensModel: filter.camera.lensModel,
takenAfter: parseOptionalDate(filter.date.takenAfter)?.startOf('day').toISO() || undefined,
takenBefore: parseOptionalDate(filter.date.takenBefore)?.endOf('day').toISO() || undefined,
visibility: filter.display.isArchive ? AssetVisibility.Archive : undefined,
Expand Down
Loading