handleSearch()
Handles user input in the search field and triggers the search process with debouncing.The search query entered by the user
Behavior
- Clears any existing search timeout to debounce rapid input
- If the query is empty, hides suggestions and applies filters to show all Pokémon
- Requires at least 2 characters to perform a search
- Debounces search execution by 300ms
- Updates search suggestions as the user types
Example
performSearch()
Executes the search operation based on the query, determining whether to use smart search or name search.The search query to process
Behavior
- Shows loading indicator during search
- Parses the query using
parseSmartSearch()to identify search criteria - If smart criteria are detected (type, color, habitat, size, weight), performs a smart search
- Otherwise, performs a name-based search
- Handles errors by displaying an error message and clearing results
- Always hides loading indicator when complete
Example
performNameSearch()
Searches for Pokémon by name, supporting partial matches.The name or partial name to search for
Behavior
- Converts query to lowercase for case-insensitive matching
- Searches through cached Pokémon first
- If no results found, attempts to fetch from API using exact name
- Sorts results by Pokémon ID
- Resets pagination to page 1
- Displays appropriate error messages if no Pokémon found
- Updates display and pagination
Example
performSmartSearch()
Executes a multi-criteria search using parsed search criteria.Object containing search criteria including:
name: string - Pokémon nametype: string - Pokémon type (fire, water, etc.)color: string - Pokémon colorhabitat: string - Pokémon habitatsize: string - Size category (tiny, small, medium, large, huge)weight: string - Weight category (light, normal, heavy, massive)
Behavior
- Loads Pokémon by type if type criterion is specified
- Applies all criteria filters to the complete Pokémon list
- Resets pagination to page 1
- Shows error if no results match criteria
- Updates display and pagination
Example
parseSmartSearch()
Parses a search query to identify and extract multiple search criteria.The raw search query to parse
Behavior
- Splits query into individual words
- Translates Spanish keywords to English API values using
searchKeywordsmap - Categorizes keywords into types, colors, habitats, sizes, and weights
- Remaining unmatched words become the name search term
- Returns structured criteria object
Example
updateSuggestions()
Generates and displays search suggestions based on the current query.The current search query
Behavior
- Matches Pokémon names containing the query (up to 3 matches)
- Matches search keywords from translations (up to 2 matches)
- Combines and limits results to maximum 5 suggestions
- Only shows suggestions if query is at least 2 characters
- Displays suggestions using
displaySuggestions()method
Example
Suggestions are displayed as clickable items that trigger a full search when selected.