Search
Status: built on phone (full-screen bar, and docked beside the rail on tablets/foldables) and TV (drawer destination with grouped rows), with Room fallback to downloads while the server is away on phone. As of 2026-11-25 (main at cbb5abb7f).
Start here
Section titled “Start here”SearchViewModel(modes/film/.../search/SearchViewModel.kt) drives search on both phone and TV over theItemListsandCurrentAccountrepository roles (SearchState,SearchAction).- On phone, search lives on the My media tab (
MediaScreen+FilmSearchBarinapp/phone/.../SearchBar.kt), with open/origin state hoisted inNavigationRoot.kt(MediaSearch) so Home’s search button opens it and closing returns to Home (#387, #394, #439). - On TV,
SearchScreen(app/tv/.../ce/presentation/film/SearchScreen.kt) is a side-drawer destination inMainScreen(#128, ADR 0002), grouping results into rows per kind (ItemKind.MOVIE,ItemKind.SERIES,ItemKind.EPISODE,ItemKind.BOX_SET). - Data path:
ItemLists.getSearchItemsinMediaRepositoryImplcallsItemListPort.search(JellyfinCatalog.searchinserver/jellyfin), falling back toStoredItemLists.search(RoomStoredLists.searchindata) on phone when the server is unreachable (#775). - Test fast:
./gradlew :modes:film:testDebugUnitTest --tests '*Search*' :app:phone:testLibreDebugUnitTest --tests '*Search*' :app:tv:testLibreDebugUnitTest --tests '*Search*'.
What it does
Section titled “What it does”Typing sends SearchAction.Search(query) to SearchViewModel. Blank queries clear items immediately; non-blank queries debounce for SearchViewModel.SEARCH_DEBOUNCE_MS (300L ms) inside currentJob, so a newer keystroke cancels any waiting request before it is sent.
MediaRepositoryImpl.getSearchItems(query, itemKinds) delegates to JellyfinCatalog.search:
- When
itemKinds == null(phone default), it queriesItemKind.MOVIE,ItemKind.SERIES,ItemKind.VIDEOandItemKind.MUSIC_VIDEOtogether up toItemListPort.SEARCH_LIMIT(50); home videos and music videos since #1076. The stored search (RoomStoredLists.search) takes the same default and tells the kinds of movie apart byMovieEntity.kind. - When
itemKinds != null(TV passes[MOVIE, SERIES, EPISODE, BOX_SET, MUSIC_VIDEO, VIDEO]viaSearchViewModel.setup, a row per kind inSearchGroup; the last two since #1076), it queries each kind in parallel withItemListPort.SEARCH_LIMIT_PER_KIND(20) per kind so episodes cannot crowd out movies, shows, or collections (#128).
On phone, MediaScreen forwards LocalServerStatus.current.unreachable to SearchViewModel.onServerAwayChanged. Using ServerAwayReload, an open non-blank search re-queries when the server goes away or comes back, and MediaRepositoryImpl falls back to RoomStoredLists.search (escaped LIKE %...% over downloaded movies, shows, and episodes in ServerDatabaseDao) and sets downloadsOnly = true (ItemsResult.fromStore). When Room answers before ServerReachability flags the outage, SearchViewModel schedules one automatic retry after ServerAwayReload.STORE_RETRY_DELAY_MS.
Across a user switch, SearchState.userId and SearchState.shownTo(LocalServerSession.current.userId) prevent showing the previous user’s results or errors for even a frame on either phone or TV, and SearchViewModel discards results if account.getUserId() changed while the request was in flight (#866).
On phone, FilmSearchBar collapses to a pill in MediaScreen, expands full-screen on compact or compact-height windows, and stays docked beside the navigation rail capped at Layout.textMaxWidth (720.dp) when useDockedSearch() is true (#439, 4-design.md). On TV, SearchScreen lays out one LazyRow per non-empty SearchGroup under a read-only-until-clicked OutlinedTextField with FocusPosition / RestoreFocus (ADR 0003) and TvLoadError on failures (#417).
Where the code is
Section titled “Where the code is”| Path | What |
|---|---|
modes/film/.../search/SearchViewModel.kt |
Shared @HiltViewModel: 300 ms debounce, setup(itemKinds), ServerAwayReload, user-switch guard |
modes/film/.../search/SearchState.kt, SearchAction.kt |
Immutable UI state (query, items, loading, error, downloadsOnly, userId, shownTo) and intents |
modes/film/.../ServerAwayReload.kt |
Tracks server-away reloads and single delayed retry after a store fallback (STORE_RETRY_DELAY_MS) |
app/phone/.../film/MediaScreen.kt |
Hosts FilmSearchBar, wires ReloadWhenServerAwayChanges, Ctrl+F, Esc, and shownTo |
app/phone/.../film/components/SearchBar.kt |
FilmSearchBar: docked vs full-screen layout, keyboard/focus rules, grid results, DownloadsOnlyLine, ErrorState, EmptyState |
app/phone/.../NavigationRoot.kt |
rememberSearchExpanded, rememberSearchFromHome, MediaSearch (Home search origin and rail/tab handling) |
app/phone/.../utils/Layout.kt |
useDockedSearch() and Layout.textMaxWidth / Layout.gridMinCell |
app/tv/.../ce/presentation/film/SearchScreen.kt |
TV search destination (SearchGroup rows, IME readOnly toggle, TvLoadError, RestoreFocus) |
app/tv/.../ce/presentation/main/MainScreen.kt |
Hosts DESTINATION_SEARCH in the drawer with SaveableStateProvider |
domain/.../ports/ItemListPort.kt |
search(query, kinds), SEARCH_LIMIT (50), SEARCH_LIMIT_PER_KIND (20) |
application/.../repository/ItemLists.kt, MediaRepositoryImpl.kt |
ItemLists.getSearchItems combining ItemListPort.search and StoredItemLists.search |
server/jellyfin/.../JellyfinCatalog.kt |
JellyfinCatalog.search and searchItems calling libraryApi.getItems(searchTerm = ...) |
application/.../repository/StoredItemLists.kt, data/.../RoomStoredLists.kt, ServerDatabaseDao.kt |
Downloaded-items search fallback via escaped SQL LIKE queries (searchMoviesOfServer, searchShowsOfServer, searchEpisodesOfServer) |
- R1, R2: no Jellyfin SDK types or
JellyfinApioutsideserver/jellyfin. Search goes throughItemLists(MediaRepositoryImpl) andItemListPort(JellyfinCatalog). - R4: no production file outside
dataimportsServerDatabaseDao(MediaRepositoryImplreads downloads throughStoredItemLists, implemented byRoomStoredLists). - R10:
ItemId,UserId, andServerIdare value classes; never use bareStringorjava.util.UUIDids outsideserver/jellyfin. - TV focus & keyboard (ADR 0003): no
LaunchedEffect(true) { focusRequester.requestFocus() }on TVSearchScreen; useFocusPosition/RestoreFocusand keep the text fieldreadOnlyuntil OK is pressed so D-pad Up from results does not open the IME. - TV has no offline mode (ADR 0007): TV
SearchScreendoes not wireServerAwayReloador showDownloadsOnlyLine.
How to test it
Section titled “How to test it”./gradlew :modes:film:testDebugUnitTest --tests '*Search*' --tests '*ServerAwayReloadTest*'./gradlew :app:phone:testLibreDebugUnitTest --tests '*Search*' :app:tv:testLibreDebugUnitTest --tests '*Search*'Unit and Robolectric tests covering search:
modes/film:SearchViewModelTest(debounce, blank query cancellation),SearchViewModelUserSwitchTest(user switch clearing,shownTo, in-flight user mismatch),ServerAwayReloadTest(server-away reloads andSTORE_RETRY_DELAY_MSretry).app/phone:MediaSearchTest(Home search origin and tab/rail rules across recreation),SearchExpandedTest(expanded state survives activity recreation),SearchBarDockedTest(docked width cap vs full-screen across window size classes),SearchBarKeyboardTest(Tab focus, Enter/typing/tap/mouse expansion, Escape shortcut).app/tv:SearchErrorTest(TvLoadErrormessage, Retry focus flow, hiding stale results on error),MainScreenTest/MainFocusReturnTest/DrawerSafeAreaTest(drawer Search destination).data&testing:StoredListsFallbackTest(Room search by name andItemKind, LIKE escaping,fromStore);ItemListContract(live/recorded server search contract).
What unit tests do not cover:
- Live Jellyfin server search relevance, ranking, or latency against
JellyfinCatalog(replay recordings live inserver/jellyfin/src/test/resources/contract/). - Real soft-keyboard (
IME) show/hide interactions on Android TV when moving betweenOutlinedTextFieldand result rows. - Physical hardware-keyboard navigation and mouse/touch transitions in
FilmSearchBaron Android devices.
Before a PR
Section titled “Before a PR”./gradlew ktfmtCheck./gradlew :modes:film:testDebugUnitTest --tests '*Search*' --tests '*ServerAwayReloadTest*'./gradlew :app:phone:testLibreDebugUnitTest --tests '*Search*' :app:tv:testLibreDebugUnitTest --tests '*Search*'./gradlew :data:testDebugUnitTest --tests '*StoredListsFallbackTest*'./gradlew :app:phone:compileLibreDebugKotlin :app:tv:compileLibreDebugKotlinIf strings changed, run python3 .claude/skills/translate-strings/scripts/check-translations.py.
Decisions and history
Section titled “Decisions and history”- #128 / #148: CE TV
SearchScreenin the side drawer withSearchViewModel.setup(itemKinds)and parallel per-kind server queries (SEARCH_LIMIT_PER_KIND = 20) so episodes do not crowd out other kinds. - #387 / #488:
rememberSearchExpandedsaved across recreation andfocusedForExpansionguard so rotation/theme switch does not collapse search or pop up the keyboard over results. - #394 / #542:
MediaSearchremembersrememberSearchFromHomeso closing a search opened from Home returns to Home. - #417 / #537: TV search shows
TvLoadError(takeFocus = false) with Retry (moving focus to the first result on success) and hides stale items on failure. - #430 / #519: Tab onto the collapsed
FilmSearchBardoes not expand it; Enter, typing, tap, or click opens it, andEsccloses it. - #439 / #536: docked search beside the navigation rail on medium/expanded non-compact-height windows (
useDockedSearch()), field capped atLayout.textMaxWidth. - #775 / #778, #779: search falls back to downloaded items in Room while the server is away (
RoomStoredLists.search,DownloadsOnlyLine,ServerAwayReload). - #866 / #873:
SearchState.userId+shownToand ViewModel user checks so another user’s results or errors never appear after a profile/user switch. - #967 / #1009: split repository/server catalog ports into
ItemListsandItemListPort.
Pitfalls
Section titled “Pitfalls”SearchState.itemskeeps the previous query’s results on error. On a failed request,SearchViewModelemits_state.value.copy(query = query, loading = false, error = e, ...), leavingitemsfrom the earlier query in state. TVSearchScreenLayoutchecksstate.error(whenquery.isNotBlank() && state.query == query) to cleargroupsand hide those stale items (#417). On phone,FilmSearchBarhides onlyDownloadsOnlyLineonstate.error != nulland still renders stalestate.itemsin theLazyVerticalGridbeneath theErrorState(EmptyState) overlay, which sets no opaque background.- Material 3’s search field expands on focus by default. Removing the
onExpandedChangeinput-mode guard orPressInteraction.Presscollector breaks keyboard Tab navigation past the collapsed bar onMediaScreen(#430). - TV
OutlinedTextFieldmust stayreadOnlywhen not actively editing. Making it editable while merely focused causes Android TV’s IME to pop open whenever D-pad Up moves from the result rows back to the field (#128). - Re-focusing on rotation pops up the keyboard over phone results.
FilmSearchBargatesfocusRequester.requestFocus()behindfocusedForExpansion(rememberSaveable) so activity recreation keeps search open without re-triggering the IME (#387). MediaSearchorigin must stay paired with rail/tab navigation. On docked tablet search, tapping My media in the rail turns a Home-originated search into a My media search, and leaving the tab clears bothexpandedandfromHome(#394, #439).- TV
SearchScreenneeds an explicit re-search after a user switch. Unlike phoneMediaScreen(whereFilmSearchBar’sLaunchedEffect(query)orMediaRoutere-entry runs), TV’sSearchScreenLayoutusesLaunchedEffect(state.userId)to re-dispatchSearchAction.Search(query)whenshownToyields the loading placeholder (#866). RoomStoredLists.searchonly searches downloaded movies, shows, and episodes. Collections (ItemKind.BOX_SET) are not stored in Room, andSearchGroup.COLLECTIONSon TV has no offline fallback (TV has no offline mode per ADR 0007).
Source: docs/areas/search.md · raw Markdown