diff --git a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt index fa988d0e9..6c483ce24 100644 --- a/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt +++ b/komga/src/main/kotlin/org/gotson/komga/domain/persistence/ReferentialRepository.kt @@ -13,10 +13,10 @@ interface ReferentialRepository { fun findAllAuthorsNamesByName(search: String, filterOnLibraryIds: Collection?): List fun findAllAuthorsRoles(filterOnLibraryIds: Collection?): List - fun findAllAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable): Page - fun findAllAuthorsByNameAndLibrary(search: String, role: String?, libraryId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page - fun findAllAuthorsByNameAndCollection(search: String, role: String?, collectionId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page - fun findAllAuthorsByNameAndSeries(search: String, role: String?, seriesId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page + fun findAllAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable): Page + fun findAllAuthorsByNameAndLibrary(search: String?, role: String?, libraryId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page + fun findAllAuthorsByNameAndCollection(search: String?, role: String?, collectionId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page + fun findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page fun findAllGenres(filterOnLibraryIds: Collection?): Set fun findAllGenresByLibrary(libraryId: String, filterOnLibraryIds: Collection?): Set 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 841e136dc..1de1cb19d 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 @@ -281,7 +281,7 @@ class BookDtoDao( private fun BookSearchWithReadProgress.toCondition(): Condition { var c: Condition = DSL.trueCondition() - searchTerm?.let { c = c.and(fts.match(it)) } + if (!searchTerm.isNullOrBlank()) c = c.and(fts.match(searchTerm)) if (!libraryIds.isNullOrEmpty()) c = c.and(b.LIBRARY_ID.`in`(libraryIds)) if (!seriesIds.isNullOrEmpty()) c = c.and(b.SERIES_ID.`in`(seriesIds)) if (!mediaStatus.isNullOrEmpty()) c = c.and(m.STATUS.`in`(mediaStatus)) diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt index 1c7573410..6a5899109 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReadListDao.kt @@ -51,8 +51,8 @@ class ReadListDao( .firstOrNull() override fun findAll(search: String?, pageable: Pageable): Page { - val conditions = search?.let { searchCondition(it) } - ?: DSL.trueCondition() + val conditions = if (!search.isNullOrBlank()) searchCondition(search) + else DSL.trueCondition() return try { val count = dsl.selectCount() @@ -87,7 +87,7 @@ class ReadListDao( override fun findAllByLibraryIds(belongsToLibraryIds: Collection, filterOnLibraryIds: Collection?, search: String?, pageable: Pageable): Page { val conditions = b.LIBRARY_ID.`in`(belongsToLibraryIds) - .apply { search?.let { and(searchCondition(it)) } } + .apply { if (!search.isNullOrBlank()) and(searchCondition(search)) } .apply { filterOnLibraryIds?.let { and(b.LIBRARY_ID.`in`(it)) } } return try { diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt index d26f1f762..d85d27250 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/ReferentialDao.kt @@ -11,6 +11,7 @@ import org.jooq.DSLContext import org.jooq.impl.DSL.field import org.jooq.impl.DSL.lower import org.jooq.impl.DSL.select +import org.jooq.impl.DSL.trueCondition import org.springframework.data.domain.Page import org.springframework.data.domain.PageImpl import org.springframework.data.domain.PageRequest @@ -82,19 +83,19 @@ class ReferentialDao( .fetchInto(bmaa) .map { it.toDomain() } - override fun findAllAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable): Page { + override fun findAllAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable): Page { return findAuthorsByName(search, role, filterOnLibraryIds, pageable, null) } - override fun findAllAuthorsByNameAndLibrary(search: String, role: String?, libraryId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { + override fun findAllAuthorsByNameAndLibrary(search: String?, role: String?, libraryId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.LIBRARY, libraryId)) } - override fun findAllAuthorsByNameAndCollection(search: String, role: String?, collectionId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { + override fun findAllAuthorsByNameAndCollection(search: String?, role: String?, collectionId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.COLLECTION, collectionId)) } - override fun findAllAuthorsByNameAndSeries(search: String, role: String?, seriesId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { + override fun findAllAuthorsByNameAndSeries(search: String?, role: String?, seriesId: String, filterOnLibraryIds: Collection?, pageable: Pageable): Page { return findAuthorsByName(search, role, filterOnLibraryIds, pageable, FilterBy(FilterByType.SERIES, seriesId)) } @@ -109,14 +110,15 @@ class ReferentialDao( val id: String, ) - private fun findAuthorsByName(search: String, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable, filterBy: FilterBy?): Page { + private fun findAuthorsByName(search: String?, role: String?, filterOnLibraryIds: Collection?, pageable: Pageable, filterBy: FilterBy?): Page { return try { val query = dsl.selectDistinct(bmaa.NAME, bmaa.ROLE) .from(bmaa) - .join(ftsAuthors).on(ftsAuthors.rowid().eq(bmaa.rowid())) + .apply { if (!search.isNullOrBlank()) join(ftsAuthors).on(ftsAuthors.rowid().eq(bmaa.rowid())) } .apply { if (filterOnLibraryIds != null || filterBy?.type == FilterByType.LIBRARY) leftJoin(s).on(bmaa.SERIES_ID.eq(s.ID)) } .apply { if (filterBy?.type == FilterByType.COLLECTION) leftJoin(cs).on(bmaa.SERIES_ID.eq(cs.SERIES_ID)) } - .where(ftsAuthors.match(search)) + .where(trueCondition()) + .apply { if (!search.isNullOrBlank()) and(ftsAuthors.match(search)) } .apply { role?.let { and(bmaa.ROLE.eq(role)) } } .apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } } .apply { @@ -130,9 +132,11 @@ class ReferentialDao( } val count = dsl.fetchCount(query) + val sort = if (!search.isNullOrBlank()) field("rank") + else lower(bmaa.NAME.udfStripAccents()) val items = query - .orderBy(field("rank")) + .orderBy(sort) .apply { if (pageable.isPaged) limit(pageable.pageSize).offset(pageable.offset) } .fetchInto(a) .map { it.toDomain() } diff --git a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt index 05abe3699..bd05075ad 100644 --- a/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt +++ b/komga/src/main/kotlin/org/gotson/komga/infrastructure/jooq/SeriesCollectionDao.kt @@ -50,8 +50,8 @@ class SeriesCollectionDao( .firstOrNull() override fun findAll(search: String?, pageable: Pageable): Page { - val conditions = search?.let { searchCondition(search) } - ?: DSL.trueCondition() + val conditions = if (!search.isNullOrBlank()) searchCondition(search) + else DSL.trueCondition() return try { val count = dsl.selectCount() @@ -86,7 +86,7 @@ class SeriesCollectionDao( override fun findAllByLibraryIds(belongsToLibraryIds: Collection, filterOnLibraryIds: Collection?, search: String?, pageable: Pageable): Page { val conditions = s.LIBRARY_ID.`in`(belongsToLibraryIds) - .apply { search?.let { and(searchCondition(it)) } } + .apply { if (!search.isNullOrBlank()) and(searchCondition(search)) } .apply { filterOnLibraryIds?.let { and(s.LIBRARY_ID.`in`(it)) } } return try { 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 1404bba48..100c7de09 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 @@ -251,7 +251,7 @@ class SeriesDtoDao( private fun SeriesSearchWithReadProgress.toCondition(): Condition { var c: Condition = DSL.trueCondition() - searchTerm?.let { c = c.and(fts.match(it)) } + if (!searchTerm.isNullOrBlank()) c = c.and(fts.match(searchTerm)) if (!libraryIds.isNullOrEmpty()) c = c.and(s.LIBRARY_ID.`in`(libraryIds)) if (!collectionIds.isNullOrEmpty()) c = c.and(cs.COLLECTION_ID.`in`(collectionIds)) searchRegex?.let { c = c.and((it.second.toColumn()).likeRegex(it.first)) } diff --git a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt index af057ebae..fcb9f5414 100644 --- a/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt +++ b/komga/src/main/kotlin/org/gotson/komga/interfaces/rest/ReferentialController.kt @@ -42,8 +42,8 @@ class ReferentialController( @GetMapping("v2/authors") fun getAuthors( @AuthenticationPrincipal principal: KomgaPrincipal, - @RequestParam(name = "search", defaultValue = "") search: String, - @RequestParam(name = "role") role: String?, + @RequestParam(name = "search", required = false) search: String?, + @RequestParam(name = "role", required = false) role: String?, @RequestParam(name = "library_id", required = false) libraryId: String?, @RequestParam(name = "collection_id", required = false) collectionId: String?, @RequestParam(name = "series_id", required = false) seriesId: String?,