feat: implement duplicate title normalized filter

This commit is contained in:
Tiberiu Ichim 2026-02-22 16:46:14 +02:00
parent aa85106681
commit ead215e777
13 changed files with 276 additions and 1 deletions

View file

@ -191,6 +191,18 @@ module.exports.getTitleIgnorePrefix = (title) => {
return getTitleParts(title)[0]
}
/**
* Get normalized title to use for grouping duplicates
* Removes non-alphabetic characters (numbers, punctuation, spaces)
* @param {string} title
* @returns {string}
*/
module.exports.getNormalizedTitle = (title) => {
if (!title) return ''
const sortTitle = getTitleParts(title)[0] || title
return sortTitle.toLowerCase().replace(/[^\p{L}]/gu, '')
}
/**
* Put sorting prefix at the end of title
* @example "The Good Book" => "Good Book, The"

View file

@ -515,6 +515,10 @@ module.exports = {
isInvalid: true
}
]
} else if (filterGroup === 'duplicates') {
libraryItemWhere['titleNormalized'] = {
[Sequelize.Op.in]: Sequelize.literal(`(SELECT titleNormalized FROM libraryItems WHERE libraryId = '${libraryId}' AND titleNormalized IS NOT NULL AND titleNormalized != '' GROUP BY titleNormalized HAVING COUNT(titleNormalized) > 1)`)
}
} else if (filterGroup === 'progress' && user) {
const mediaProgressWhere = {
userId: user.id

View file

@ -168,6 +168,10 @@ module.exports = {
isInvalid: true
}
]
} else if (filterGroup === 'duplicates') {
libraryItemWhere['titleNormalized'] = {
[Sequelize.Op.in]: Sequelize.literal(`(SELECT titleNormalized FROM libraryItems WHERE libraryId = '${libraryId}' AND titleNormalized IS NOT NULL AND titleNormalized != '' GROUP BY titleNormalized HAVING COUNT(titleNormalized) > 1)`)
}
} else if (filterGroup === 'recent') {
libraryItemWhere['createdAt'] = {
[Sequelize.Op.gte]: new Date(new Date() - 60 * 24 * 60 * 60 * 1000) // 60 days ago