Initial Commit 2
This commit is contained in:
17
src/song.rs
17
src/song.rs
@ -1,4 +1,6 @@
|
||||
use crate::fuzzy::{self, FuzzyScore};
|
||||
use serde::Deserialize;
|
||||
use std::cmp::max;
|
||||
|
||||
#[derive(Deserialize, Debug, Clone, Default)]
|
||||
pub struct Song {
|
||||
@ -16,3 +18,18 @@ pub struct Song {
|
||||
#[serde(rename = "duetsingerp2")]
|
||||
pub duet_singer_2: Option<String>,
|
||||
}
|
||||
|
||||
impl Song {
|
||||
pub fn duet(&self) -> Option<(&str, &str)> {
|
||||
self.duet_singer_1
|
||||
.as_deref()
|
||||
.zip(self.duet_singer_2.as_deref())
|
||||
}
|
||||
|
||||
pub fn fuzzy_compare(&self, query: &str) -> FuzzyScore {
|
||||
let title_score = fuzzy::compare(self.title.chars(), query.chars());
|
||||
let artist_score = fuzzy::compare(self.artist.chars(), query.chars());
|
||||
|
||||
max(title_score, artist_score)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user