From 656f433b9d1d1d7c9b33e6fc48ebf5a2b92fe00a Mon Sep 17 00:00:00 2001 From: Gauthier Roebroeck Date: Fri, 4 Feb 2022 11:46:02 +0800 Subject: [PATCH] fix: filtering may not work with some unicode characters use collation instead of lowercase comparison closes #789 --- .../org/gotson/komga/infrastructure/jooq/BookDtoDao.kt | 3 +-- .../org/gotson/komga/infrastructure/jooq/SeriesDao.kt | 3 ++- .../org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt index ea6891614..cc4038b18 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/BookDtoDao.kt @@ -25,7 +25,6 @@ import org.jooq.Record import org.jooq.ResultQuery import org.jooq.impl.DSL import org.jooq.impl.DSL.inline -import org.jooq.impl.DSL.lower import org.jooq.impl.DSL.noCondition import org.springframework.data.domain.Page import org.springframework.data.domain.PageImpl @@ -329,7 +328,7 @@ class BookDtoDao( if (deleted == true) c = c.and(b.DELETED_DATE.isNotNull) if (deleted == false) c = c.and(b.DELETED_DATE.isNull) if (releasedAfter != null) c = c.and(d.RELEASE_DATE.gt(releasedAfter)) - if (!tags.isNullOrEmpty()) c = c.and(lower(bt.TAG).`in`(tags.map { it.lowercase() })) + if (!tags.isNullOrEmpty()) c = c.and(bt.TAG.collate(SqliteUdfDataSource.collationUnicode3).`in`(tags)) if (readStatus != null) { val cr = readStatus.map { diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt index 7f54d1266..a52e70c8e 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDao.kt @@ -3,6 +3,7 @@ package org.gotson.komga.infrastructure.jooq import org.gotson.komga.domain.model.Series import org.gotson.komga.domain.model.SeriesSearch import org.gotson.komga.domain.persistence.SeriesRepository +import org.gotson.komga.infrastructure.datasource.SqliteUdfDataSource import org.gotson.komga.jooq.Tables import org.gotson.komga.jooq.tables.records.SeriesRecord import org.jooq.Condition @@ -141,7 +142,7 @@ class SeriesDao( searchTerm?.let { c = c.and(d.TITLE.containsIgnoreCase(it)) } searchRegex?.let { c = c.and((it.second.toColumn()).likeRegex(it.first)) } if (!metadataStatus.isNullOrEmpty()) c = c.and(d.STATUS.`in`(metadataStatus)) - if (!publishers.isNullOrEmpty()) c = c.and(DSL.lower(d.PUBLISHER).`in`(publishers.map { it.lowercase() })) + if (!publishers.isNullOrEmpty()) c = c.and(d.PUBLISHER.collate(SqliteUdfDataSource.collationUnicode3).`in`(publishers)) if (deleted == true) c = c.and(s.DELETED_DATE.isNotNull) if (deleted == false) c = c.and(s.DELETED_DATE.isNull) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt index c227330fc..fe1f2ad6a 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesDtoDao.kt @@ -259,14 +259,14 @@ class SeriesDtoDao( if (!collectionIds.isNullOrEmpty()) c = c.and(cs.COLLECTION_ID.`in`(collectionIds)) searchRegex?.let { c = c.and((it.second.toColumn()).likeRegex(it.first)) } if (!metadataStatus.isNullOrEmpty()) c = c.and(d.STATUS.`in`(metadataStatus)) - if (!publishers.isNullOrEmpty()) c = c.and(lower(d.PUBLISHER).`in`(publishers.map { it.lowercase() })) + if (!publishers.isNullOrEmpty()) c = c.and(d.PUBLISHER.collate(SqliteUdfDataSource.collationUnicode3).`in`(publishers)) if (deleted == true) c = c.and(s.DELETED_DATE.isNotNull) if (deleted == false) c = c.and(s.DELETED_DATE.isNull) if (complete == false) c = c.and(d.TOTAL_BOOK_COUNT.isNotNull.and(d.TOTAL_BOOK_COUNT.ne(s.BOOK_COUNT))) if (complete == true) c = c.and(d.TOTAL_BOOK_COUNT.isNotNull.and(d.TOTAL_BOOK_COUNT.eq(s.BOOK_COUNT))) - if (!languages.isNullOrEmpty()) c = c.and(lower(d.LANGUAGE).`in`(languages.map { it.lowercase() })) - if (!genres.isNullOrEmpty()) c = c.and(lower(g.GENRE).`in`(genres.map { it.lowercase() })) - if (!tags.isNullOrEmpty()) c = c.and(lower(st.TAG).`in`(tags.map { it.lowercase() }).or(lower(bmat.TAG).`in`(tags.map { it.lowercase() }))) + if (!languages.isNullOrEmpty()) c = c.and(d.LANGUAGE.collate(SqliteUdfDataSource.collationUnicode3).`in`(languages)) + if (!genres.isNullOrEmpty()) c = c.and(g.GENRE.collate(SqliteUdfDataSource.collationUnicode3).`in`(genres)) + if (!tags.isNullOrEmpty()) c = c.and(st.TAG.collate(SqliteUdfDataSource.collationUnicode3).`in`(tags).or(bmat.TAG.collate(SqliteUdfDataSource.collationUnicode3).`in`(tags))) if (!ageRatings.isNullOrEmpty()) { val c1 = if (ageRatings.contains(null)) d.AGE_RATING.isNull else DSL.noCondition() val c2 = if (ageRatings.filterNotNull().isNotEmpty()) d.AGE_RATING.`in`(ageRatings.filterNotNull()) else DSL.noCondition()