Compare commits
3 Commits
06e12c186a
...
3800b448e1
| Author | SHA1 | Date | |
|---|---|---|---|
|
3800b448e1
|
|||
|
4a6bb957a1
|
|||
|
666f87a5f3
|
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
Dockerfile
|
||||
target
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -587,7 +587,7 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
|
||||
|
||||
[[package]]
|
||||
name = "singit2"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"css_typegen",
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "singit2"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
authors = ["Joakim Hulthe <joakim@hulthe.net"]
|
||||
edition = "2021"
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
##################
|
||||
### BASE STAGE ###
|
||||
##################
|
||||
FROM rust:1.57 as base
|
||||
FROM rust:1.60 as base
|
||||
|
||||
# Install build dependencies
|
||||
RUN cargo install --locked trunk strip_cargo_version
|
||||
|
||||
12
src/app.rs
12
src/app.rs
@ -183,8 +183,16 @@ pub fn view(model: &Model) -> Vec<Node<Msg>> {
|
||||
],
|
||||
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],
|
||||
|
||||
21
src/query.rs
21
src/query.rs
@ -11,10 +11,10 @@ pub struct ParsedQuery<'a> {
|
||||
pub plain: Option<Cow<'a, str>>,
|
||||
|
||||
/// Query a specific title
|
||||
pub title: Option<&'a str>,
|
||||
pub title: Option<Cow<'a, str>>,
|
||||
|
||||
/// Query a specific artist
|
||||
pub artist: Option<&'a str>,
|
||||
pub artist: Option<Cow<'a, str>>,
|
||||
|
||||
/// Whether the song is a duet
|
||||
pub duet: Option<bool>,
|
||||
@ -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
|
||||
},
|
||||
];
|
||||
|
||||
13
src/song.rs
13
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user