mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-07 18:01:42 +00:00
Update author filter to use normalized search name
This commit is contained in:
parent
a28241e735
commit
c2316fae81
1 changed files with 12 additions and 2 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
const Sequelize = require('sequelize')
|
const Sequelize = require('sequelize')
|
||||||
const Database = require('../../Database')
|
const Database = require('../../Database')
|
||||||
|
const Author = require('../../models/Author')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/**
|
/**
|
||||||
|
|
@ -60,10 +61,19 @@ module.exports = {
|
||||||
* @returns {Promise<Object[]>} oldAuthor with numBooks
|
* @returns {Promise<Object[]>} oldAuthor with numBooks
|
||||||
*/
|
*/
|
||||||
async search(libraryId, query, limit, offset) {
|
async search(libraryId, query, limit, offset) {
|
||||||
const matchAuthor = query.matchExpression('name')
|
const normalizedQuery = Author.normalizeSearchName(query.query)
|
||||||
|
if (!normalizedQuery) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
const authors = await Database.authorModel.findAll({
|
const authors = await Database.authorModel.findAll({
|
||||||
where: {
|
where: {
|
||||||
[Sequelize.Op.and]: [Sequelize.literal(matchAuthor), { libraryId }]
|
[Sequelize.Op.and]: [
|
||||||
|
Sequelize.where(Sequelize.col('searchName'), {
|
||||||
|
[Sequelize.Op.substring]: normalizedQuery
|
||||||
|
}),
|
||||||
|
{ libraryId }
|
||||||
|
]
|
||||||
},
|
},
|
||||||
attributes: {
|
attributes: {
|
||||||
include: [[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']]
|
include: [[Sequelize.literal('(SELECT count(*) FROM bookAuthors ba WHERE ba.authorId = author.id)'), 'numBooks']]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue