Use distinctBy filter to show unique searches

This commit is contained in:
deborahlow97 2020-03-14 14:12:27 +08:00
parent dd28c4145d
commit f4d1091fb9

View File

@ -34,13 +34,12 @@ class NewRecentSearchDao @Inject constructor(
orderDesc(RecentSearchEntity_.id)
}
).map { searchEntities ->
searchEntities.distinct()
searchEntities.distinctBy(RecentSearchEntity::searchTerm)
.take(NUM_RECENT_RESULTS)
.map { searchEntity -> RecentSearchListItem(searchEntity.searchTerm) }
}
fun saveSearch(title: String, id: String) {
deleteSearchString(title)
box.put(RecentSearchEntity(searchTerm = title, zimId = id))
}