Package-level declarations

Media search.

Search

The search mechanism is described by the Search interface.

val photoManager: PhotoManager
val search: Search = photoManager.search

Build Suggestions Flow

The search process begins with creating a search Flow.

val search: Search
val searchQueryStateFlow = MutableStateFlow("") // Set search query with it
val configuration = SuggestionSearchConfiguration(
language = "en", // Query lang abbreviation. Important "in" -> "id"
debounceTime = 300 // Flow debounce parameter
)

lifecycleScope.launch(Dispatchers.IO) {
search.createSuggestionsContainerFlow(
userId = 0L,
searchQueryStateFlow = searchQueryStateFlow,
configuration = configuration
).collect { container -> // container: SuggestionsContainer
// Handle it...
}
}

Suggestion

When the request is modified, the stream returns a container of suggestions. By selecting the desired suggestion, you can obtain its contents as follows.

val search: Search

lifecycleScope.launch(Dispatchers.IO) {

// Clear previous results before retrieving content
search.clearLocalSearchResults()

// Fetch content from one suggestion
search.fetchSuggestionContent(
userId = 0L,
request = SuggestionContentRequest(
suggestionId = "id",
contentType = SuggestionContentType.MEDIA
)
)

// Or fetch content of few suggestions
search.fetchSuggestionsContent(
userId = 0L,
requests = listOf(
SuggestionContentRequest(
suggestionId = "id1",
contentType = SuggestionContentType.MEDIA
),
SuggestionContentRequest(
suggestionId = "id2",
contentType = SuggestionContentType.VIDEO
),
SuggestionContentRequest(
suggestionId = "id3",
contentType = SuggestionContentType.VIDEO
),
)
)
}

All the obtained results are stored in the database and retrieved using flow.

Media Search Result Listing

val search: Search

lifecycleScope.launch(Dispatchers.IO) {
// search.createMediaPagingFlow - Paging media list
// search.createSectionMediaFlow - Media list with createdAt in range
// search.createMonthlyMediaSectionsGroupedByYearsFlow - Sorted list of months and the number
// of photos in each of them
}

Album Search Result Listing

val search: Search

lifecycleScope.launch(Dispatchers.IO) {
// search.createAlbumsFlow - Albums list flow
// search.createAlbumsPagingFlow - Paging albums list
}

Types

Link copied to clipboard
interface Search
Link copied to clipboard
data class Suggestion(val id: String, val name: String, val type: Suggestion.Type, val subType: String, val lang: String, val createdAt: Long, val updatedAt: Long, val covers: List<AlbumCover>) : Parcelable
Link copied to clipboard
data class SuggestionContentRequest(val suggestionId: String, val contentType: SuggestionContentType)
Link copied to clipboard
data class SuggestionsContainer(val persons: List<Suggestion>, val addresses: List<Suggestion>, val albums: List<Suggestion>, val calendars: List<Suggestion>, val labels: List<Suggestion>, val moments: List<Suggestion>) : Parcelable
Link copied to clipboard
data class SuggestionSearchConfiguration(val language: String, val debounceTime: Long = 300)