Skip to content

Commit

Permalink
Fixed suggestions.
Browse files Browse the repository at this point in the history
  • Loading branch information
anikiki committed Oct 21, 2024
1 parent d0e983b commit 24d6f50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,23 +168,23 @@ class AutoCompleteApi @Inject constructor(
}.take(maximumNumberOfTopHits)

val maxBottomSection = maximumNumberOfSuggestions - (topHits.size + minimumNumberInSuggestionGroup)
val filteredBookmarks =
val filteredBookmarksAndTabsAndHistory =
bookmarksAndTabsAndHistory
.filter { suggestion -> topHits.none { it.phrase == suggestion.phrase } }
.take(maxBottomSection)
val maxSearchResults = maximumNumberOfSuggestions - (topHits.size + filteredBookmarks.size)
val maxSearchResults = maximumNumberOfSuggestions - (topHits.size + filteredBookmarksAndTabsAndHistory.size)
val filteredSearchResults = searchResults
.filter { searchSuggestion -> filteredBookmarks.none { it.phrase == searchSuggestion.phrase } }
.filter { searchSuggestion -> filteredBookmarksAndTabsAndHistory.none { it.phrase == searchSuggestion.phrase } }
.take(maxSearchResults)

val inAppMessage = mutableListOf<AutoCompleteSuggestion>()

val suggestions = (topHits + filteredSearchResults + filteredBookmarks).distinctBy {
Pair<String, Class<out AutoCompleteSuggestion>>(
it.phrase,
it::class.java,
)
val distinctPhrases = (topHits + filteredBookmarksAndTabsAndHistory).distinctBy { it.phrase }.map { it.phrase }.toSet()
val distinctSearchResults = filteredSearchResults.distinctBy { it.phrase }.filterNot { it.phrase in distinctPhrases }
val suggestions = (topHits + distinctSearchResults + filteredBookmarksAndTabsAndHistory).distinctBy {
Pair(it.phrase, it::class.java)
}

runBlocking(dispatcherProvider.io()) {
if (shouldShowHistoryInAutoCompleteIAM(suggestions)) {
inAppMessage.add(0, AutoCompleteInAppMessageSuggestion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,7 @@ class AutoCompleteApiTest {

assertEquals(
listOf(
AutoCompleteBookmarkSuggestion(
phrase = "foo.com?key=value",
"title foo",
"https://foo.com?key=value",
),
AutoCompleteBookmarkSuggestion(phrase = "foo.com?key=value", "title foo", "https://foo.com?key=value"),
AutoCompleteBookmarkSuggestion(phrase = "foo.com", "title foo", "https://foo.com"),
AutoCompleteSearchSuggestion(phrase = "example.com", false),
AutoCompleteSearchSuggestion(phrase = "baz.com", true),
Expand Down

0 comments on commit 24d6f50

Please sign in to comment.