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,
|
||||
}
|
||||
|
||||
#[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)]
|
||||
enum SearchScope {
|
||||
All,
|
||||
Library {
|
||||
title: String,
|
||||
query: core::jellyfin::LibraryQuery, // includes item types
|
||||
query: core::jellyfin::LibraryQuery,
|
||||
},
|
||||
}
|
||||
|
||||
struct SearchState {
|
||||
mode: SearchMode,
|
||||
scope: SearchScope,
|
||||
input: String,
|
||||
}
|
||||
@@ -257,8 +314,10 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// build query based on scope
|
||||
let (title, query) = match &search.scope {
|
||||
let mode = search.mode;
|
||||
let types = mode.include_item_types().map(|s| s.to_string());
|
||||
|
||||
let (title, mut query) = match &search.scope {
|
||||
SearchScope::All => (
|
||||
format!("Search: {}", term),
|
||||
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;
|
||||
|
||||
// run search (same as your library fetch)
|
||||
@@ -297,6 +359,10 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
||||
|
||||
return;
|
||||
}
|
||||
KeyCode::Char('/') => {
|
||||
search.mode = search.mode.next();
|
||||
return;
|
||||
}
|
||||
KeyCode::Char(c) => { search.input.push(c); return; }
|
||||
_ => return,
|
||||
}
|
||||
@@ -455,7 +521,11 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
||||
_ => 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(),
|
||||
};
|
||||
|
||||
let mode = s.mode.label();
|
||||
|
||||
if s.input.is_empty() {
|
||||
format!("/ ({scope})")
|
||||
format!("/ ({scope}) [{mode}]")
|
||||
} else {
|
||||
format!("/ ({scope}) {}", s.input)
|
||||
format!("/ ({scope}) [{mode}] {}", s.input)
|
||||
}
|
||||
} else {
|
||||
app.status.clone()
|
||||
|
||||
Reference in New Issue
Block a user