diff --git a/src/app.rs b/src/app.rs index 90135f1..d63dd73 100644 --- a/src/app.rs +++ b/src/app.rs @@ -183,8 +183,16 @@ pub fn view(model: &Model) -> Vec> { ], div![ C![C.song_item_info], - div![C![C.song_item_title], song.title.to_string()], - div![C![C.song_item_artist], song.artist.to_string()], + div![C![C.song_item_title], &song.title], + div![ + C![C.song_item_artist], + span![&song.artist], + if let Some(year) = song.year.as_ref() { + span![" (", year, ")"] + } else { + empty![] + } + ], ], div![ C![C.song_gizmos], diff --git a/src/query.rs b/src/query.rs index 742c911..b21f150 100644 --- a/src/query.rs +++ b/src/query.rs @@ -11,10 +11,10 @@ pub struct ParsedQuery<'a> { pub plain: Option>, /// Query a specific title - pub title: Option<&'a str>, + pub title: Option>, /// Query a specific artist - pub artist: Option<&'a str>, + pub artist: Option>, /// Whether the song is a duet pub duet: Option, @@ -43,8 +43,8 @@ impl<'a> ParsedQuery<'a> { for (k, v) in kvs { match k { - "title" => parsed.title = Some(v), - "artist" => parsed.artist = Some(v), + "title" => parsed.title = Some(Cow::Borrowed(v)), + "artist" => parsed.artist = Some(Cow::Borrowed(v)), "duet" => parsed.duet = parse_bool(v), "video" => parsed.video = parse_bool(v), "lang" => parsed.language = Some(v), @@ -62,6 +62,15 @@ impl<'a> ParsedQuery<'a> { let until_space = |s: &'a str| -> &'a str { s.trim().split_whitespace().next().unwrap_or("") }; + let join_spaces = |s: &'a str| -> Cow<'a, str> { + let s = s.trim(); + if s.contains(char::is_whitespace) { + s.replace(char::is_whitespace, "").into() + } else { + Cow::Borrowed(s) + } + }; + let mut primary_fields: [&dyn Fn(Self) -> Self; 4] = [ &|query| Self { plain: Some(Cow::Borrowed(&song.title)), @@ -72,11 +81,11 @@ impl<'a> ParsedQuery<'a> { ..query }, &|query| Self { - title: Some(until_space(&song.title)), + title: Some(join_spaces(&song.title)), ..query }, &|query| Self { - artist: Some(until_space(&song.artist)), + artist: Some(join_spaces(&song.artist)), ..query }, ]; diff --git a/src/song.rs b/src/song.rs index 6326389..0b30ed4 100644 --- a/src/song.rs +++ b/src/song.rs @@ -35,14 +35,13 @@ impl Song { match item { Some(item) => { let score = fuzzy::compare(item.chars(), query.chars()); - if score < fuzzy::max_score(query) / 2 { - return false; - } + score == fuzzy::max_score(query) } - None => return false, + None => false, } + } else { + true } - true }; let filter_bool = @@ -67,12 +66,12 @@ impl Song { score = max(title_score, artist_score); } - if let Some(title) = query.title { + if let Some(title) = &query.title { let new_score = fuzzy::compare(self.title.chars(), title.chars()); score = max(score, new_score); } - if let Some(artist) = query.artist { + if let Some(artist) = &query.artist { let new_score = fuzzy::compare(self.artist.chars(), artist.chars()); score = max(score, new_score); }