mirror of
https://github.com/gotson/komga.git
synced 2025-12-20 07:23:34 +01:00
feat: ignore accents and multiple whitespace when sorting books
close s#702
This commit is contained in:
parent
f592a9eda2
commit
cebdef1e58
2 changed files with 19 additions and 7 deletions
|
|
@ -28,6 +28,7 @@ import org.gotson.komga.domain.persistence.SeriesCollectionRepository
|
|||
import org.gotson.komga.domain.persistence.SeriesMetadataRepository
|
||||
import org.gotson.komga.domain.persistence.SeriesRepository
|
||||
import org.gotson.komga.domain.persistence.ThumbnailSeriesRepository
|
||||
import org.gotson.komga.infrastructure.language.stripAccents
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import java.io.File
|
||||
|
|
@ -54,6 +55,8 @@ class SeriesLifecycle(
|
|||
private val transactionTemplate: TransactionTemplate,
|
||||
) {
|
||||
|
||||
private val whitespacePattern = """\s+""".toRegex()
|
||||
|
||||
fun sortBooks(series: Series) {
|
||||
logger.debug { "Sorting books for $series" }
|
||||
|
||||
|
|
@ -63,7 +66,14 @@ class SeriesLifecycle(
|
|||
logger.debug { "Existing metadata: $metadatas" }
|
||||
|
||||
val sorted = books
|
||||
.sortedWith(compareBy(natSortComparator) { it.name })
|
||||
.sortedWith(
|
||||
compareBy(natSortComparator) {
|
||||
it.name
|
||||
.trim()
|
||||
.stripAccents()
|
||||
.replace(whitespacePattern, " ")
|
||||
}
|
||||
)
|
||||
.map { book -> book to metadatas.first { it.bookId == book.id } }
|
||||
logger.debug { "Sorted books: $sorted" }
|
||||
|
||||
|
|
|
|||
|
|
@ -72,9 +72,11 @@ class SeriesLifecycleTest(
|
|||
// given
|
||||
val books = listOf(
|
||||
makeBook("book 1", libraryId = library.id),
|
||||
makeBook("book 05", libraryId = library.id),
|
||||
makeBook("book 6", libraryId = library.id),
|
||||
makeBook("book 002", libraryId = library.id)
|
||||
makeBook("boôk 05", libraryId = library.id),
|
||||
makeBook(" book 3", libraryId = library.id),
|
||||
makeBook("book 4 ", libraryId = library.id),
|
||||
makeBook("book 6", libraryId = library.id),
|
||||
makeBook("book 002", libraryId = library.id)
|
||||
)
|
||||
val createdSeries = makeSeries(name = "series", libraryId = library.id).let {
|
||||
seriesLifecycle.createSeries(it)
|
||||
|
|
@ -86,11 +88,11 @@ class SeriesLifecycleTest(
|
|||
|
||||
// then
|
||||
assertThat(seriesRepository.count()).isEqualTo(1)
|
||||
assertThat(bookRepository.count()).isEqualTo(4)
|
||||
assertThat(bookRepository.count()).isEqualTo(6)
|
||||
|
||||
val savedBooks = bookRepository.findAllBySeriesId(createdSeries.id).sortedBy { it.number }
|
||||
assertThat(savedBooks.map { it.name }).containsExactly("book 1", "book 002", "book 05", "book 6")
|
||||
assertThat(savedBooks.map { it.number }).containsExactly(1, 2, 3, 4)
|
||||
assertThat(savedBooks.map { it.name }).containsExactly("book 1", "book 002", " book 3", "book 4 ", "boôk 05", "book 6")
|
||||
assertThat(savedBooks.map { it.number }).containsExactly(1, 2, 3, 4, 5, 6)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in a new issue