Fix format issues

recent_search
Takeshi Hagikura 2 years ago
parent 6f9d2fe3ba
commit 477838f9da

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

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

@ -44,5 +44,5 @@ fun TopicEntity.asFtsEntity() = TopicFtsEntity(
topicId = id, topicId = id,
name = name, name = name,
shortDescription = shortDescription, 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 com.google.samples.apps.nowinandroid.core.model.data.UserData
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flow
import javax.inject.Inject import javax.inject.Inject
class GetSearchContentsUseCase @Inject constructor( class GetSearchContentsUseCase @Inject constructor(

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

Loading…
Cancel
Save