From 4f5d045960b042eb27e10bac1bdaf1c074c9fa2a Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Thu, 23 Jul 2020 21:30:04 +0200 Subject: harmonize search for libraries --- server/models/video/video-channel.ts | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'server/models/video/video-channel.ts') diff --git a/server/models/video/video-channel.ts b/server/models/video/video-channel.ts index f3401fb9c..9da965bbc 100644 --- a/server/models/video/video-channel.ts +++ b/server/models/video/video-channel.ts @@ -315,9 +315,8 @@ export class VideoChannelModel extends Model { start: number count: number sort: string - search?: string }) { - const { actorId, search } = parameters + const { actorId } = parameters const query = { offset: parameters.start, @@ -326,7 +325,7 @@ export class VideoChannelModel extends Model { } const scopes = { - method: [ ScopeNames.FOR_API, { actorId, search } as AvailableForListOptions ] + method: [ ScopeNames.FOR_API, { actorId } as AvailableForListOptions ] } return VideoChannelModel .scope(scopes) @@ -405,7 +404,23 @@ export class VideoChannelModel extends Model { count: number sort: string withStats?: boolean + search?: string }) { + const escapedSearch = VideoModel.sequelize.escape(options.search) + const escapedLikeSearch = VideoModel.sequelize.escape('%' + options.search + '%') + const where = options.search + ? { + [Op.or]: [ + Sequelize.literal( + 'lower(immutable_unaccent("VideoChannelModel"."name")) % lower(immutable_unaccent(' + escapedSearch + '))' + ), + Sequelize.literal( + 'lower(immutable_unaccent("VideoChannelModel"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' + ) + ] + } + : null + const query = { offset: options.start, limit: options.count, @@ -418,7 +433,8 @@ export class VideoChannelModel extends Model { }, required: true } - ] + ], + where } const scopes: string | ScopeOptions | (string | ScopeOptions)[] = [ ScopeNames.WITH_ACTOR ] -- cgit v1.2.3