Skip to content

Commit 56b95e7

Browse files
committed
Search: Filter artwork data and image size
1 parent d1e47f7 commit 56b95e7

File tree

4 files changed

+119
-29
lines changed

4 files changed

+119
-29
lines changed

crates/core-api-json/src/track/search.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ impl From<_inner::StringField> for StringField {
190190
#[serde(rename_all = "camelCase")]
191191
pub enum NumericField {
192192
AdvisoryRating,
193+
ArtworkDataSize,
194+
ArtworkImageHeight,
195+
ArtworkImageWidth,
193196
AudioBitrateBps,
194197
AudioChannelCount,
195198
AudioChannelMask,
@@ -212,13 +215,16 @@ impl From<NumericField> for _inner::NumericField {
212215
fn from(from: NumericField) -> Self {
213216
use NumericField as From;
214217
match from {
218+
From::AdvisoryRating => Self::AdvisoryRating,
219+
From::ArtworkDataSize => Self::ArtworkDataSize,
220+
From::ArtworkImageHeight => Self::ArtworkImageHeight,
221+
From::ArtworkImageWidth => Self::ArtworkImageWidth,
215222
From::AudioBitrateBps => Self::AudioBitrateBps,
216223
From::AudioChannelCount => Self::AudioChannelCount,
217224
From::AudioChannelMask => Self::AudioChannelMask,
218225
From::AudioDurationMs => Self::AudioDurationMs,
219226
From::AudioSampleRateHz => Self::AudioSampleRateHz,
220227
From::AudioLoudnessLufs => Self::AudioLoudnessLufs,
221-
From::AdvisoryRating => Self::AdvisoryRating,
222228
From::DiscNumber => Self::DiscNumber,
223229
From::DiscTotal => Self::DiscTotal,
224230
From::MusicTempoBpm => Self::MusicTempoBpm,
@@ -237,13 +243,16 @@ impl From<_inner::NumericField> for NumericField {
237243
fn from(from: _inner::NumericField) -> Self {
238244
use _inner::NumericField as From;
239245
match from {
246+
From::AdvisoryRating => Self::AdvisoryRating,
247+
From::ArtworkDataSize => Self::ArtworkDataSize,
248+
From::ArtworkImageHeight => Self::ArtworkImageHeight,
249+
From::ArtworkImageWidth => Self::ArtworkImageWidth,
240250
From::AudioBitrateBps => Self::AudioBitrateBps,
241251
From::AudioChannelCount => Self::AudioChannelCount,
242252
From::AudioChannelMask => Self::AudioChannelMask,
243253
From::AudioDurationMs => Self::AudioDurationMs,
244254
From::AudioSampleRateHz => Self::AudioSampleRateHz,
245255
From::AudioLoudnessLufs => Self::AudioLoudnessLufs,
246-
From::AdvisoryRating => Self::AdvisoryRating,
247256
From::DiscNumber => Self::DiscNumber,
248257
From::DiscTotal => Self::DiscTotal,
249258
From::MusicTempoBpm => Self::MusicTempoBpm,

crates/core-api/src/track/search.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@ pub enum StringField {
2424

2525
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2626
pub enum NumericField {
27+
AdvisoryRating,
28+
ArtworkDataSize,
29+
ArtworkImageHeight,
30+
ArtworkImageWidth,
2731
AudioBitrateBps,
2832
AudioChannelCount,
2933
AudioChannelMask,
3034
AudioDurationMs,
3135
AudioLoudnessLufs,
3236
AudioSampleRateHz,
33-
AdvisoryRating,
3437
DiscNumber,
3538
DiscTotal,
3639
MusicTempoBpm,

crates/repo-sqlite/src/repo/track/search.rs

+100-25
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,106 @@ fn build_numeric_field_filter_expression(
367367
#[allow(clippy::enum_glob_use)]
368368
use ScalarPredicate::*;
369369
match filter.field {
370+
AdvisoryRating => {
371+
let expr = view_track_search::advisory_rating;
372+
let expr_not_null = ifnull(expr, encode_advisory_rating(Default::default()));
373+
// TODO: Check and limit/clamp value range when converting from f64 to i16
374+
match filter.predicate {
375+
LessThan(value) => Box::new(expr_not_null.lt(value as i16)),
376+
LessOrEqual(value) => Box::new(expr_not_null.le(value as i16)),
377+
GreaterThan(value) => Box::new(expr_not_null.gt(value as i16)),
378+
GreaterOrEqual(value) => Box::new(expr_not_null.ge(value as i16)),
379+
Equal(value) => {
380+
if let Some(value) = value {
381+
Box::new(expr_not_null.eq(value as i16))
382+
} else {
383+
Box::new(expr.is_null())
384+
}
385+
}
386+
NotEqual(value) => {
387+
if let Some(value) = value {
388+
Box::new(expr_not_null.ne(value as i16))
389+
} else {
390+
Box::new(expr.is_not_null())
391+
}
392+
}
393+
}
394+
}
395+
ArtworkDataSize => {
396+
let expr = view_track_search::artwork_data_size;
397+
let expr_not_null = ifnull(expr, 0);
398+
// TODO: Check and limit/clamp value range when converting from f64 to i64
399+
match filter.predicate {
400+
LessThan(value) => Box::new(expr_not_null.lt(value as i64)),
401+
LessOrEqual(value) => Box::new(expr_not_null.le(value as i64)),
402+
GreaterThan(value) => Box::new(expr_not_null.gt(value as i64)),
403+
GreaterOrEqual(value) => Box::new(expr_not_null.ge(value as i64)),
404+
Equal(value) => {
405+
if let Some(value) = value {
406+
Box::new(expr_not_null.eq(value as i64))
407+
} else {
408+
Box::new(expr.is_null())
409+
}
410+
}
411+
NotEqual(value) => {
412+
if let Some(value) = value {
413+
Box::new(expr_not_null.ne(value as i64))
414+
} else {
415+
Box::new(expr.is_not_null())
416+
}
417+
}
418+
}
419+
}
420+
ArtworkImageHeight => {
421+
let expr = view_track_search::artwork_image_height;
422+
let expr_not_null = ifnull(expr, 0);
423+
// TODO: Check and limit/clamp value range when converting from f64 to i16
424+
match filter.predicate {
425+
LessThan(value) => Box::new(expr_not_null.lt(value as i16)),
426+
LessOrEqual(value) => Box::new(expr_not_null.le(value as i16)),
427+
GreaterThan(value) => Box::new(expr_not_null.gt(value as i16)),
428+
GreaterOrEqual(value) => Box::new(expr_not_null.ge(value as i16)),
429+
Equal(value) => {
430+
if let Some(value) = value {
431+
Box::new(expr_not_null.eq(value as i16))
432+
} else {
433+
Box::new(expr.is_null())
434+
}
435+
}
436+
NotEqual(value) => {
437+
if let Some(value) = value {
438+
Box::new(expr_not_null.ne(value as i16))
439+
} else {
440+
Box::new(expr.is_not_null())
441+
}
442+
}
443+
}
444+
}
445+
ArtworkImageWidth => {
446+
let expr = view_track_search::artwork_image_width;
447+
let expr_not_null = ifnull(expr, 0);
448+
// TODO: Check and limit/clamp value range when converting from f64 to i16
449+
match filter.predicate {
450+
LessThan(value) => Box::new(expr_not_null.lt(value as i16)),
451+
LessOrEqual(value) => Box::new(expr_not_null.le(value as i16)),
452+
GreaterThan(value) => Box::new(expr_not_null.gt(value as i16)),
453+
GreaterOrEqual(value) => Box::new(expr_not_null.ge(value as i16)),
454+
Equal(value) => {
455+
if let Some(value) = value {
456+
Box::new(expr_not_null.eq(value as i16))
457+
} else {
458+
Box::new(expr.is_null())
459+
}
460+
}
461+
NotEqual(value) => {
462+
if let Some(value) = value {
463+
Box::new(expr_not_null.ne(value as i16))
464+
} else {
465+
Box::new(expr.is_not_null())
466+
}
467+
}
468+
}
469+
}
370470
AudioDurationMs => {
371471
let expr = view_track_search::audio_duration_ms;
372472
let expr_not_null = ifnull(expr, DurationMs::empty().value());
@@ -513,31 +613,6 @@ fn build_numeric_field_filter_expression(
513613
}
514614
}
515615
}
516-
AdvisoryRating => {
517-
let expr = view_track_search::advisory_rating;
518-
let expr_not_null = ifnull(expr, encode_advisory_rating(Default::default()));
519-
// TODO: Check and limit/clamp value range when converting from f64 to i16
520-
match filter.predicate {
521-
LessThan(value) => Box::new(expr_not_null.lt(value as i16)),
522-
LessOrEqual(value) => Box::new(expr_not_null.le(value as i16)),
523-
GreaterThan(value) => Box::new(expr_not_null.gt(value as i16)),
524-
GreaterOrEqual(value) => Box::new(expr_not_null.ge(value as i16)),
525-
Equal(value) => {
526-
if let Some(value) = value {
527-
Box::new(expr_not_null.eq(value as i16))
528-
} else {
529-
Box::new(expr.is_null())
530-
}
531-
}
532-
NotEqual(value) => {
533-
if let Some(value) = value {
534-
Box::new(expr_not_null.ne(value as i16))
535-
} else {
536-
Box::new(expr.is_not_null())
537-
}
538-
}
539-
}
540-
}
541616
TrackNumber => {
542617
let expr = view_track_search::track_number;
543618
let expr_not_null = ifnull(expr, 0);

websrv/res/openapi.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2034,13 +2034,16 @@ components:
20342034
NumericField:
20352035
type: string
20362036
enum:
2037+
- advisoryRating
2038+
- artworkDataSize
2039+
- artworkImageHeight
2040+
- artworkImageWidth
20372041
- audioBitrateBps
20382042
- audioChannelCount
20392043
- audioChannelMask
20402044
- audioDurationMs
20412045
- audioLoudnessLufs
20422046
- audioSampleRateHz
2043-
- advisoryRating
20442047
- discNumber
20452048
- discTotal
20462049
- musicTempoBpm

0 commit comments

Comments
 (0)