getRecentSearches method

List<String> getRecentSearches({
  1. int limit = 10,
})

Retrieves recent search history.

Returns a list of search queries ordered by recency and usage count. The limit parameter controls how many items to return.

Implementation

List<String> getRecentSearches({int limit = 10}) {
  _ensureInitialized();

  final items = _box!.values.toList();
  items.sort((a, b) {
    // Sort by timestamp descending, then by count descending
    final timeCompare = b.timestamp.compareTo(a.timestamp);
    if (timeCompare != 0) return timeCompare;
    return b.count.compareTo(a.count);
  });

  return items.take(limit).map((item) => item.query).toList();
}