diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 521d79b51..204083bfe 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -31,7 +31,14 @@ interface BookSourceDao { ) fun flowSearchEnabled(searchKey: String): Flow> - @Query("select * from book_sources where bookSourceGroup like '%' || :searchKey || '%' order by customOrder asc") + @Query( + """select * from book_sources + where bookSourceGroup = :searchKey + or bookSourceGroup like :searchKey || ',%' + or bookSourceGroup like '%,' || :searchKey + or bookSourceGroup like '%,' || :searchKey || ',%' + order by customOrder asc""" + ) fun flowGroupSearch(searchKey: String): Flow> @Query("select * from book_sources where enabled = 1 order by customOrder asc") @@ -50,7 +57,8 @@ interface BookSourceDao { """select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' - and (bookSourceGroup like '%' || :key || '%' or bookSourceName like '%' || :key || '%') + and (bookSourceGroup like '%' || :key || '%' + or bookSourceName like '%' || :key || '%') order by customOrder asc""" ) fun flowExplore(key: String): Flow> @@ -59,7 +67,10 @@ interface BookSourceDao { """select * from book_sources where enabledExplore = 1 and trim(exploreUrl) <> '' - and (bookSourceGroup like '%' || :key || '%') + and (bookSourceGroup = :key + or bookSourceGroup like :key || ',%' + or bookSourceGroup like '%,' || :key + or bookSourceGroup like '%,' || :key || ',%') order by customOrder asc""" ) fun flowGroupExplore(key: String): Flow> diff --git a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt index 709127642..d56f11bde 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssSourceDao.kt @@ -22,10 +22,23 @@ interface RssSourceDao { @Query("SELECT * FROM rssSources order by customOrder") fun flowAll(): Flow> - @Query("SELECT * FROM rssSources where sourceName like :key or sourceUrl like :key or sourceGroup like :key order by customOrder") + @Query( + """SELECT * FROM rssSources + where sourceName like '%' || :key || '%' + or sourceUrl like '%' || :key || '%' + or sourceGroup like '%' || :key || '%' + order by customOrder""" + ) fun flowSearch(key: String): Flow> - @Query("SELECT * FROM rssSources where sourceGroup like :key order by customOrder") + @Query( + """SELECT * FROM rssSources + where (sourceGroup = :key + or sourceGroup like :key || ',%' + or sourceGroup like '%,' || :key + or sourceGroup like '%,' || :key || ',%') + order by customOrder""" + ) fun flowGroupSearch(key: String): Flow> @Query("SELECT * FROM rssSources where enabled = 1 order by customOrder") @@ -34,12 +47,21 @@ interface RssSourceDao { @Query( """SELECT * FROM rssSources where enabled = 1 - and (sourceName like :searchKey or sourceGroup like :searchKey or sourceUrl like :searchKey) + and (sourceName like '%' || :searchKey || '%' + or sourceGroup like '%' || :searchKey || '%' + or sourceUrl like '%' || :searchKey || '%') order by customOrder""" ) fun flowEnabled(searchKey: String): Flow> - @Query("SELECT * FROM rssSources where enabled = 1 and sourceGroup like :searchKey order by customOrder") + @Query( + """SELECT * FROM rssSources + where enabled = 1 and (sourceGroup = :searchKey + or sourceGroup like :searchKey || ',%' + or sourceGroup like '%,' || :searchKey + or sourceGroup like '%,' || :searchKey || ',%') + order by customOrder""" + ) fun flowEnabledByGroup(searchKey: String): Flow> @Query("select distinct sourceGroup from rssSources where trim(sourceGroup) <> ''") diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 4faf5173a..9630f1752 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -140,9 +140,9 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), searchKey.isNullOrEmpty() -> appDb.rssSourceDao.flowEnabled() searchKey.startsWith("group:") -> { val key = searchKey.substringAfter("group:") - appDb.rssSourceDao.flowEnabledByGroup("%$key%") + appDb.rssSourceDao.flowEnabledByGroup(key) } - else -> appDb.rssSourceDao.flowEnabled("%$searchKey%") + else -> appDb.rssSourceDao.flowEnabled(searchKey) }.catch { AppLog.put("订阅界面更新数据出错", it) }.collect { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index 3a636654a..61872cd0e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -242,10 +242,10 @@ class RssSourceActivity : VMBaseActivity { val key = searchKey.substringAfter("group:") - appDb.rssSourceDao.flowGroupSearch("%$key%") + appDb.rssSourceDao.flowGroupSearch(key) } else -> { - appDb.rssSourceDao.flowSearch("%$searchKey%") + appDb.rssSourceDao.flowSearch(searchKey) } }.catch { AppLog.put("订阅源管理界面更新数据出错", it)