Compare commits

...

3 Commits

Author SHA1 Message Date
3800b448e1 0.2.2 2022-04-19 15:15:00 +02:00
4a6bb957a1 Update dockerfile & add .dockerignore 2022-04-19 15:14:40 +02:00
666f87a5f3 Improve searching and search hints 2022-04-19 15:10:24 +02:00
7 changed files with 36 additions and 18 deletions

2
.dockerignore Normal file
View File

@ -0,0 +1,2 @@
Dockerfile
target

2
Cargo.lock generated
View File

@ -587,7 +587,7 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]] [[package]]
name = "singit2" name = "singit2"
version = "0.2.1" version = "0.2.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"css_typegen", "css_typegen",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "singit2" name = "singit2"
version = "0.2.1" version = "0.2.2"
authors = ["Joakim Hulthe <joakim@hulthe.net"] authors = ["Joakim Hulthe <joakim@hulthe.net"]
edition = "2021" edition = "2021"

View File

@ -1,7 +1,7 @@
################## ##################
### BASE STAGE ### ### BASE STAGE ###
################## ##################
FROM rust:1.57 as base FROM rust:1.60 as base
# Install build dependencies # Install build dependencies
RUN cargo install --locked trunk strip_cargo_version RUN cargo install --locked trunk strip_cargo_version

View File

@ -183,8 +183,16 @@ pub fn view(model: &Model) -> Vec<Node<Msg>> {
], ],
div![ div![
C![C.song_item_info], C![C.song_item_info],
div![C![C.song_item_title], song.title.to_string()], div![C![C.song_item_title], &song.title],
div![C![C.song_item_artist], song.artist.to_string()], div![
C![C.song_item_artist],
span![&song.artist],
if let Some(year) = song.year.as_ref() {
span![" (", year, ")"]
} else {
empty![]
}
],
], ],
div![ div![
C![C.song_gizmos], C![C.song_gizmos],

View File

@ -11,10 +11,10 @@ pub struct ParsedQuery<'a> {
pub plain: Option<Cow<'a, str>>, pub plain: Option<Cow<'a, str>>,
/// Query a specific title /// Query a specific title
pub title: Option<&'a str>, pub title: Option<Cow<'a, str>>,
/// Query a specific artist /// Query a specific artist
pub artist: Option<&'a str>, pub artist: Option<Cow<'a, str>>,
/// Whether the song is a duet /// Whether the song is a duet
pub duet: Option<bool>, pub duet: Option<bool>,
@ -43,8 +43,8 @@ impl<'a> ParsedQuery<'a> {
for (k, v) in kvs { for (k, v) in kvs {
match k { match k {
"title" => parsed.title = Some(v), "title" => parsed.title = Some(Cow::Borrowed(v)),
"artist" => parsed.artist = Some(v), "artist" => parsed.artist = Some(Cow::Borrowed(v)),
"duet" => parsed.duet = parse_bool(v), "duet" => parsed.duet = parse_bool(v),
"video" => parsed.video = parse_bool(v), "video" => parsed.video = parse_bool(v),
"lang" => parsed.language = Some(v), "lang" => parsed.language = Some(v),
@ -62,6 +62,15 @@ impl<'a> ParsedQuery<'a> {
let until_space = let until_space =
|s: &'a str| -> &'a str { s.trim().split_whitespace().next().unwrap_or("") }; |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] = [ let mut primary_fields: [&dyn Fn(Self) -> Self; 4] = [
&|query| Self { &|query| Self {
plain: Some(Cow::Borrowed(&song.title)), plain: Some(Cow::Borrowed(&song.title)),
@ -72,11 +81,11 @@ impl<'a> ParsedQuery<'a> {
..query ..query
}, },
&|query| Self { &|query| Self {
title: Some(until_space(&song.title)), title: Some(join_spaces(&song.title)),
..query ..query
}, },
&|query| Self { &|query| Self {
artist: Some(until_space(&song.artist)), artist: Some(join_spaces(&song.artist)),
..query ..query
}, },
]; ];

View File

@ -35,14 +35,13 @@ impl Song {
match item { match item {
Some(item) => { Some(item) => {
let score = fuzzy::compare(item.chars(), query.chars()); let score = fuzzy::compare(item.chars(), query.chars());
if score < fuzzy::max_score(query) / 2 { score == fuzzy::max_score(query)
return false;
}
} }
None => return false, None => false,
} }
} else {
true
} }
true
}; };
let filter_bool = let filter_bool =
@ -67,12 +66,12 @@ impl Song {
score = max(title_score, artist_score); 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()); let new_score = fuzzy::compare(self.title.chars(), title.chars());
score = max(score, new_score); 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()); let new_score = fuzzy::compare(self.artist.chars(), artist.chars());
score = max(score, new_score); score = max(score, new_score);
} }