Improve database search
This commit is contained in:
parent
a3b1d2571e
commit
f7b220f933
@ -33,7 +33,7 @@
|
||||
],
|
||||
"env" : {
|
||||
"CARGO_HOME" : "/run/build/Podcasts/cargo",
|
||||
"RUSTFLAGS" : "--error-format=human --remap-path-prefix =../",
|
||||
"RUSTFLAGS" : "--error-format=short --remap-path-prefix =../",
|
||||
"RUST_BACKTRACE" : "1"
|
||||
}
|
||||
},
|
||||
|
||||
@ -87,13 +87,20 @@ pub(crate) fn get_downloaded_episodes() -> Result<Vec<EpisodeCleanerModel>, Data
|
||||
.map_err(From::from)
|
||||
}
|
||||
|
||||
pub fn search_episodes(term: &str) -> Result<Vec<Episode>, DataError> {
|
||||
// Only searches from downloaded episodes
|
||||
pub fn search_episodes(terms: Vec<&str>) -> Result<Vec<Episode>, DataError> {
|
||||
use crate::schema::episodes::dsl::*;
|
||||
let db = connection();
|
||||
let con = db.get()?;
|
||||
|
||||
let mut search_term = "".to_string();
|
||||
for term in terms {
|
||||
search_term.push_str(&format!( "%{}%", term));
|
||||
}
|
||||
|
||||
episodes
|
||||
.filter(title.like(format!("%{}%", term)))
|
||||
.filter(local_uri.is_not_null())
|
||||
.filter(title.like(&search_term))
|
||||
.order(epoch.desc())
|
||||
.load::<Episode>(&con)
|
||||
.map_err(From::from)
|
||||
|
||||
@ -72,21 +72,13 @@ impl SearchProvider {
|
||||
sender
|
||||
.send(Action::InitEpisode(episode.rowid()))
|
||||
.expect("Action channel blew up somehow");
|
||||
// TODO: Sometimes it's necessary to download the episode first. Otherwise it cannot be played.
|
||||
// TODO: Greyout title state doesn't get applied.
|
||||
});
|
||||
|
||||
self.search_provider
|
||||
.connect_get_initial_result_set(|terms| {
|
||||
let term = terms.join("");
|
||||
Self::search(term)
|
||||
});
|
||||
.connect_get_initial_result_set(|terms| Self::search(terms));
|
||||
|
||||
self.search_provider
|
||||
.connect_get_subsearch_result_set(|_, terms| {
|
||||
let term = terms.join("");
|
||||
Self::search(term)
|
||||
});
|
||||
.connect_get_subsearch_result_set(|_, terms| Self::search(terms));
|
||||
|
||||
self.search_provider.connect_get_result_metas(|sp_ids| {
|
||||
let mut metas = Vec::new();
|
||||
@ -117,8 +109,8 @@ impl SearchProvider {
|
||||
});
|
||||
}
|
||||
|
||||
fn search(term: String) -> Vec<String> {
|
||||
let episodes = dbqueries::search_episodes(&term)
|
||||
fn search(terms: Vec<&str>) -> Vec<String> {
|
||||
let episodes = dbqueries::search_episodes(terms)
|
||||
.expect("Could not search for episodes (search provider)");
|
||||
|
||||
let mut sp_ids = Vec::new();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user