Fix format issues

recent_search
Takeshi Hagikura 1 year ago
parent 6f9d2fe3ba
commit 477838f9da

@ -41,16 +41,16 @@ class DefaultSearchContentsRepository @Inject constructor(
override fun searchContents(searchQuery: String): Flow<SearchResult> {
// Surround the query by asterisks to match the query when it's in the middle of
// a word
val newsResourceIds = newsResourceFtsDao.searchAllNewsResources("*${searchQuery}*")
val topicIds = topicFtsDao.searchAllTopics("*${searchQuery}*")
val newsResourceIds = newsResourceFtsDao.searchAllNewsResources("*$searchQuery*")
val topicIds = topicFtsDao.searchAllTopics("*$searchQuery*")
return combine(
newsResourceDao.getNewsResources(filterNewsIds = newsResourceIds.toSet()),
topicDao.getTopicEntities(topicIds.toSet())
topicDao.getTopicEntities(topicIds.toSet()),
) { newsResources, topics ->
SearchResult(
topics = topics.map { it.asExternalModel() },
newsResources = newsResources.map { it.asExternalModel() }
newsResources = newsResources.map { it.asExternalModel() },
)
}
}

@ -24,8 +24,7 @@ import javax.inject.Inject
/**
* Fake implementation of the [SearchContentsRepository]
*/
class FakeSearchContentsRepository @Inject constructor(
) : SearchContentsRepository {
class FakeSearchContentsRepository @Inject constructor() : SearchContentsRepository {
override fun populateFtsData() {}
override fun searchContents(searchQuery: String): Flow<SearchResult> {

@ -29,6 +29,7 @@ import com.google.samples.apps.nowinandroid.core.database.model.TopicFtsEntity
interface TopicFtsDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAll(topics: List<TopicFtsEntity>)
@Query("SELECT topicId FROM topicsFts WHERE topicsFts MATCH :query")
fun searchAllTopics(query: String): List<String>

@ -44,5 +44,5 @@ fun TopicEntity.asFtsEntity() = TopicFtsEntity(
topicId = id,
name = name,
shortDescription = shortDescription,
longDescription = longDescription
longDescription = longDescription,
)

@ -24,8 +24,6 @@ import com.google.samples.apps.nowinandroid.core.domain.model.UserNewsResource
import com.google.samples.apps.nowinandroid.core.model.data.UserData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flow
import javax.inject.Inject
class GetSearchContentsUseCase @Inject constructor(

@ -44,7 +44,6 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -100,7 +99,7 @@ internal fun SearchRoute(
onSearchQueryChanged = searchViewModel::onSearchQueryChanged,
onTopicClick = onTopicClick,
onNewsResourcesCheckedChanged = forYouViewModel::updateNewsResourceSaved,
uiState = uiState
uiState = uiState,
)
}

Loading…
Cancel
Save