From 0ee5922ba66c33d9757fceefacb2a6eb52c86dc8 Mon Sep 17 00:00:00 2001 From: cwj3rcb Date: Sat, 14 Feb 2026 02:48:02 -0600 Subject: [PATCH] created more robust search engine --- here.zip | Bin 0 -> 158 bytes src/main.rs | 84 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 here.zip diff --git a/here.zip b/here.zip new file mode 100644 index 0000000000000000000000000000000000000000..ca80fa0835da2cc670d5ac511904f75a560b81b9 GIT binary patch literal 158 zcmWIWW@h1H0D-0rzA<11lwe_yVJI$2)(;KgWMDS_(w}Jp#HAJ742&!C$rM1VIV nlN>WH{Sr`<1Q^~rf|wA~SRtlin8eBkQo{&@UO?Io#9;sc2ObzU literal 0 HcmV?d00001 diff --git a/src/main.rs b/src/main.rs index 2ca06d2..78e40ef 100644 --- a/src/main.rs +++ b/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()