Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 339a792c rédigé par Kubat's avatar Kubat
Parcourir les fichiers

DATABASE: Finish to implement the new search thingy (need to test it!)

parent 9ea434d5
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!197Draft: Refactor the whole code.
......@@ -56,6 +56,29 @@ impl SearchBy {
_ => vec![],
}
}
/// A match function.
pub(crate) fn matches(&self, kara: &Kara) -> bool {
match &self {
SearchBy::Query(regex) => regex.is_match(&kara.to_title_string()),
SearchBy::Id(id) => kara.id.local_id().eq(id),
SearchBy::SongType(ty) => kara.song_type.eq(ty),
SearchBy::SongOrigin(ori) => kara.song_origin.eq(ori),
SearchBy::Author(author) => kara.kara_makers.contains(author.as_str()),
SearchBy::Tag((key, None)) => kara.tags.contains_key(key.as_str()),
SearchBy::Tag((key, Some(value))) => kara
.tags
.get(key.as_str())
.map(|v| v.iter().any(|v| v.as_ref().eq(value.as_str())))
.unwrap_or_default(),
// Recursive thing to apply multiple filters.
SearchBy::Multiple(filters) => filters.iter().all(|filter| filter.matches(kara)),
// Handled after...
SearchBy::Playlist(_) => true,
}
}
}
impl Search {
......@@ -73,19 +96,6 @@ impl Search {
/// A match function.
pub(crate) fn matches(&self, kara: &Kara) -> bool {
match &self.0 {
SearchBy::Query(regex) => regex.is_match(&kara.to_title_string()),
SearchBy::Id(id) => kara.id.local_id().eq(id),
SearchBy::SongType(ty) => kara.song_type.eq(ty),
SearchBy::SongOrigin(ori) => kara.song_origin.eq(ori),
SearchBy::Author(_) => todo!(),
SearchBy::Tag(_) => todo!(),
SearchBy::Multiple(_) => todo!(),
// Handled after...
SearchBy::Playlist(_) => true,
}
self.0.matches(kara)
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter