Overview
ScreenPulse’s search feature allows users to find movies, TV shows, and series using the OMDB (Open Movie Database) API. The search system supports title search, type filtering, year filtering, and pagination.Key Components
- OmdbService (
src/app/shared/services/omdb/omdb.service.ts) - Handles OMDB API requests - SearchComponent (
src/app/pages/search/page/search.component.ts) - Main search page - SearchBarComponent - Search form with filters
- MovieResultsTableComponent - Displays search results
Search Service
TheOmdbService provides methods to interact with the OMDB API:
src/app/shared/services/omdb/omdb.service.ts
Search Parameters
Available Filters
The title of the movie or TV show to search for. Automatically trimmed of whitespace.
Filter by media type:
all- Search all typesmovie- Movies onlyseries- TV series onlyepisode- Episodes only
Filter by release year (e.g., “2020”). Leave empty to search all years.
Page number for pagination. Each page returns up to 10 results.
Performing a Search
User submits search form
The user enters search criteria in the
SearchBarComponent and submits the form:src/app/pages/search/page/search.component.ts
Call OMDB API through service
The component calls the
OmdbService with search parameters:src/app/pages/search/page/search.component.ts
Search State Management
TheSearchComponent maintains search state using a SearchState interface:
src/app/pages/search/page/search.component.ts
State Properties
- title - Current search query
- type - Selected media type filter
- year - Selected year filter
- currentPage - Current pagination page
- pageSize - Results per page (fixed at 10)
- collection - Array of search results
- collectionSize - Total number of results available
- searchOnProcess - Loading state indicator
Pagination
Handle pagination by updating the current page and re-fetching results:src/app/pages/search/page/search.component.ts
response.totalResults.
Viewing Media Details
Click on a search result to open a detailed view with additional information:src/app/pages/search/page/search.component.ts
Adding to Favorites from Search
Users can add items directly from search results:src/app/pages/search/page/search.component.ts
Users must be logged in to add items to favorites. The function checks authentication status before proceeding.
Featured Media
The search page displays featured media items from a predefined constant:src/app/pages/search/page/search.component.ts
API Integration
The OMDB API is accessed through a proxy endpoint configured in the environment:src/environments/environment.development.ts
API Response Format
Search Response:Error Handling
No Results Found
No Results Found
When the API returns no results:Common error messages:
- “Movie not found!” - No results match the search criteria
- “Too many results” - Search is too broad, add more filters
API Connection Error
API Connection Error
If the backend server is unreachable:
Invalid Parameters
Invalid Parameters
The service automatically trims the title and converts parameters to strings:
Search Results Table
The search results are displayed in a table with the following columns:src/app/pages/search/page/search.component.ts
- Title - Movie or TV show title
- Year - Release year
- Type - Media type (movie, series, episode)
- Poster - Thumbnail image
- Add - Button to add to favorites
Best Practices
Trim Search Input
Always trim whitespace from search titles to avoid API errors and improve search accuracy.
Handle Loading States
Use
searchOnProcess to show loading indicators and prevent duplicate requests.Check Authentication
Verify users are logged in before allowing them to add items to favorites.
Implement Pagination
Display pagination controls when
collectionSize exceeds pageSize to help users navigate results.Example Usage
Basic Search
Search with Filters
Get Detailed Information
Related Files
src/app/shared/services/omdb/omdb.service.ts- OMDB API servicesrc/app/pages/search/page/search.component.ts- Search page componentsrc/app/pages/search/components/search-bar/search-bar.component.ts- Search formsrc/app/pages/search/components/movie-results-table/movie-results-table.component.ts- Results tablesrc/app/pages/search/components/carousel/carousel.component.ts- Featured media carouselsrc/environments/environment.development.ts- Environment configuration