aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video.ts')
-rw-r--r--server/models/video/video.ts37
1 files changed, 33 insertions, 4 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 27e73bbf1..3a3cfbe85 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -93,7 +93,6 @@ import { VideoShareModel } from './video-share'
93import { VideoTagModel } from './video-tag' 93import { VideoTagModel } from './video-tag'
94import { ScheduleVideoUpdateModel } from './schedule-video-update' 94import { ScheduleVideoUpdateModel } from './schedule-video-update'
95import { VideoCaptionModel } from './video-caption' 95import { VideoCaptionModel } from './video-caption'
96import { VideosSearchQuery } from '../../../shared/models/search'
97 96
98// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation 97// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
99const indexes: Sequelize.DefineIndexesOptions[] = [ 98const indexes: Sequelize.DefineIndexesOptions[] = [
@@ -848,7 +847,7 @@ export class VideoModel extends Model<VideoModel> {
848 } 847 }
849 848
850 static async searchAndPopulateAccountAndServer (options: { 849 static async searchAndPopulateAccountAndServer (options: {
851 search: string 850 search?: string
852 start?: number 851 start?: number
853 count?: number 852 count?: number
854 sort?: string 853 sort?: string
@@ -883,11 +882,41 @@ export class VideoModel extends Model<VideoModel> {
883 whereAnd.push({ duration: durationRange }) 882 whereAnd.push({ duration: durationRange })
884 } 883 }
885 884
886 whereAnd.push(createSearchTrigramQuery('VideoModel.name', options.search)) 885 const attributesInclude = []
886 if (options.search) {
887 whereAnd.push(
888 {
889 [ Sequelize.Op.or ]: [
890 createSearchTrigramQuery('VideoModel.name', options.search),
891
892 {
893 id: {
894 [ Sequelize.Op.in ]: Sequelize.literal(
895 '(' +
896 'SELECT "video"."id" FROM "video" LEFT JOIN "videoTag" ON "videoTag"."videoId" = "video"."id" ' +
897 'INNER JOIN "tag" ON "tag"."id" = "videoTag"."tagId" ' +
898 'WHERE "tag"."name" = ' + VideoModel.sequelize.escape(options.search) +
899 ')'
900 )
901 }
902 }
903 ]
904 }
905 )
906
907 attributesInclude.push(createSimilarityAttribute('VideoModel.name', options.search))
908 }
909
910 // Cannot search on similarity if we don't have a search
911 if (!options.search) {
912 attributesInclude.push(
913 Sequelize.literal('0 as similarity')
914 )
915 }
887 916
888 const query: IFindOptions<VideoModel> = { 917 const query: IFindOptions<VideoModel> = {
889 attributes: { 918 attributes: {
890 include: [ createSimilarityAttribute('VideoModel.name', options.search) ] 919 include: attributesInclude
891 }, 920 },
892 offset: options.start, 921 offset: options.start,
893 limit: options.count, 922 limit: options.count,