Overview
The recent searches feature provides:- Recent Searches: Automatically saved searches that users can quickly access
- Favorite Searches: Users can star important pages for quick access
- Local Storage: All data is stored locally in the browser
- Automatic Management: Old searches are automatically removed when limits are reached
How It Works
When the search modal is opened with no query, DocSearch displays:- Favorite searches (if any)
- Recent searches (most recent first)
- Recent conversations (if Ask AI is enabled)
Recent and favorite searches are stored in the browser’s
localStorage using the key pattern __DOCSEARCH_FAVORITE_SEARCHES__ and __DOCSEARCH_RECENT_SEARCHES__.Configuration
Disable User Personalization
You can completely disable the recent searches feature:disableUserPersonalization is true:
- No searches are saved to localStorage
- No recent/favorite searches are displayed
- The empty state shows immediately when opening with no query
Customize Limits
Control how many recent searches are stored and displayed:recentSearchesLimit: 7 (when no favorites exist)recentSearchesWithFavoritesLimit: 4 (when favorites exist)
Storage Implementation
DocSearch uses a plugin-based storage system to manage recent and favorite searches.Storage Plugin Interface
The storage system provides these methods:Creating Storage
Internal implementation creates separate storage for recent and favorite searches:Add Recent Search
When a user selects a search result, it’s automatically added to recent searches:add method:
- Removes highlight and snippet data before storing
- Checks if the item already exists (by
objectID) - Moves existing items to the top of the list
- Limits the total stored items to the configured limit
Remove Search
Users can remove individual recent searches by clicking the X icon:Get All Searches
Retrieve all stored searches:Data Structure
Recent searches are stored as simplified hit objects:LocalStorage Management
DocSearch implements automatic quota management to prevent localStorage errors.Quota Exceeded Handling
When localStorage quota is exceeded:- DocSearch automatically cleans up old data
- Removes the largest stored items first
- Retries the storage operation
Proactive Cleanup
DocSearch monitors localStorage usage and proactively cleans up when approaching limits:Recent Conversations (Ask AI)
When Ask AI is enabled, DocSearch also stores recent conversations:- The original query
- All messages in the conversation thread
- User feedback (likes/dislikes)
User Experience
Empty State
When the modal opens with no query and no recent searches:Favorite Searches
Users can favorite a search by:- Hovering over a result in the modal
- Clicking the star icon that appears
- The item is moved from recent searches to favorites
Removing Searches
Users can remove items by:- Hovering over a recent or favorite search
- Clicking the X icon
- The item is removed from localStorage
Privacy Considerations
All recent searches and favorites are stored locally in the user’s browser. No search history is sent to Algolia servers beyond the regular search API calls.
- Complete user privacy
- Works offline (for viewing history)
- No server-side storage or syncing
- Users control their data via browser settings
- History is not synced across devices or browsers
- Clearing browser data removes all history
- Private/incognito mode may have restrictions
Browser Compatibility
DocSearch automatically detects localStorage support:- Recent searches feature gracefully degrades
- No errors are thrown
- Search functionality remains fully operational
Best Practices
Set appropriate limits
Balance between providing useful history and not overwhelming users. The defaults (7 recent, 4 with favorites) work well for most cases.
Consider disabling for sensitive docs
If your documentation contains sensitive information, consider setting
disableUserPersonalization={true}.Test in private browsing
Some browsers restrict localStorage in private/incognito mode. Test that your implementation gracefully handles this.
