created more robust search engine
This commit is contained in:
84
src/main.rs
84
src/main.rs
@@ -43,16 +43,73 @@ enum LoginFocus {
|
|||||||
Pass,
|
Pass,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
enum SearchMode {
|
||||||
|
All, // no filter (true "all")
|
||||||
|
ShowsMovies, // Movie + Series
|
||||||
|
Shows, // Series
|
||||||
|
Movies, // Movie
|
||||||
|
Episodes, // Episode
|
||||||
|
Music, // Audio
|
||||||
|
Albums, // MusicAlbum
|
||||||
|
Artists, // MusicArtist
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SearchMode {
|
||||||
|
fn next(self) -> Self {
|
||||||
|
use SearchMode::*;
|
||||||
|
match self {
|
||||||
|
All => ShowsMovies,
|
||||||
|
ShowsMovies => Shows,
|
||||||
|
Shows => Movies,
|
||||||
|
Movies => Episodes,
|
||||||
|
Episodes => Music,
|
||||||
|
Music => Albums,
|
||||||
|
Albums => Artists,
|
||||||
|
Artists => All,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn label(self) -> &'static str {
|
||||||
|
use SearchMode::*;
|
||||||
|
match self {
|
||||||
|
All => "All",
|
||||||
|
ShowsMovies => "Shows+Movies",
|
||||||
|
Shows => "Shows",
|
||||||
|
Movies => "Movies",
|
||||||
|
Episodes => "Episodes",
|
||||||
|
Music => "Music",
|
||||||
|
Albums => "Albums",
|
||||||
|
Artists => "Artists",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn include_item_types(self) -> Option<&'static str> {
|
||||||
|
use SearchMode::*;
|
||||||
|
match self {
|
||||||
|
All => None, // IMPORTANT: truly unfiltered
|
||||||
|
ShowsMovies => Some("Movie,Series"),
|
||||||
|
Shows => Some("Series"),
|
||||||
|
Movies => Some("Movie"),
|
||||||
|
Episodes => Some("Episode"),
|
||||||
|
Music => Some("Audio"),
|
||||||
|
Albums => Some("MusicAlbum"),
|
||||||
|
Artists => Some("MusicArtist"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
enum SearchScope {
|
enum SearchScope {
|
||||||
All,
|
All,
|
||||||
Library {
|
Library {
|
||||||
title: String,
|
title: String,
|
||||||
query: core::jellyfin::LibraryQuery, // includes item types
|
query: core::jellyfin::LibraryQuery,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SearchState {
|
struct SearchState {
|
||||||
|
mode: SearchMode,
|
||||||
scope: SearchScope,
|
scope: SearchScope,
|
||||||
input: String,
|
input: String,
|
||||||
}
|
}
|
||||||
@@ -257,8 +314,10 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// build query based on scope
|
let mode = search.mode;
|
||||||
let (title, query) = match &search.scope {
|
let types = mode.include_item_types().map(|s| s.to_string());
|
||||||
|
|
||||||
|
let (title, mut query) = match &search.scope {
|
||||||
SearchScope::All => (
|
SearchScope::All => (
|
||||||
format!("Search: {}", term),
|
format!("Search: {}", term),
|
||||||
core::jellyfin::LibraryQuery::all().with_search(term.clone()),
|
core::jellyfin::LibraryQuery::all().with_search(term.clone()),
|
||||||
@@ -269,6 +328,9 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Override/force item types for the search mode
|
||||||
|
query.include_item_types = types;
|
||||||
|
|
||||||
app.search = None;
|
app.search = None;
|
||||||
|
|
||||||
// run search (same as your library fetch)
|
// run search (same as your library fetch)
|
||||||
@@ -297,6 +359,10 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
KeyCode::Char('/') => {
|
||||||
|
search.mode = search.mode.next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
KeyCode::Char(c) => { search.input.push(c); return; }
|
KeyCode::Char(c) => { search.input.push(c); return; }
|
||||||
_ => return,
|
_ => return,
|
||||||
}
|
}
|
||||||
@@ -455,7 +521,11 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
|||||||
_ => SearchScope::All,
|
_ => SearchScope::All,
|
||||||
};
|
};
|
||||||
|
|
||||||
app.search = Some(SearchState { scope, input: String::new() });
|
app.search = Some(SearchState {
|
||||||
|
scope,
|
||||||
|
mode: SearchMode::All,
|
||||||
|
input: String::new(),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => {}
|
_ => {}
|
||||||
@@ -574,10 +644,12 @@ fn ui(frame: &mut Frame, app: &App) {
|
|||||||
SearchScope::Library { title, .. } => title.clone(),
|
SearchScope::Library { title, .. } => title.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mode = s.mode.label();
|
||||||
|
|
||||||
if s.input.is_empty() {
|
if s.input.is_empty() {
|
||||||
format!("/ ({scope})")
|
format!("/ ({scope}) [{mode}]")
|
||||||
} else {
|
} else {
|
||||||
format!("/ ({scope}) {}", s.input)
|
format!("/ ({scope}) [{mode}] {}", s.input)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
app.status.clone()
|
app.status.clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user