aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video.ts92
1 files changed, 37 insertions, 55 deletions
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 74a3a5d05..15b4dda5b 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -83,7 +83,7 @@ import { AccountVideoRateModel } from '../account/account-video-rate'
83import { ActorModel } from '../activitypub/actor' 83import { ActorModel } from '../activitypub/actor'
84import { AvatarModel } from '../avatar/avatar' 84import { AvatarModel } from '../avatar/avatar'
85import { ServerModel } from '../server/server' 85import { ServerModel } from '../server/server'
86import { getSort, throwIfNotValid } from '../utils' 86import { buildTrigramSearchIndex, createSearchTrigramQuery, createSimilarityAttribute, getSort, throwIfNotValid } from '../utils'
87import { TagModel } from './tag' 87import { TagModel } from './tag'
88import { VideoAbuseModel } from './video-abuse' 88import { VideoAbuseModel } from './video-abuse'
89import { VideoChannelModel } from './video-channel' 89import { VideoChannelModel } from './video-channel'
@@ -94,6 +94,37 @@ import { 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'
96 96
97// FIXME: Define indexes here because there is an issue with TS and Sequelize.literal when called directly in the annotation
98const indexes: Sequelize.DefineIndexesOptions[] = [
99 buildTrigramSearchIndex('video_name_trigram', 'name'),
100
101 {
102 fields: [ 'createdAt' ]
103 },
104 {
105 fields: [ 'duration' ]
106 },
107 {
108 fields: [ 'views' ]
109 },
110 {
111 fields: [ 'likes' ]
112 },
113 {
114 fields: [ 'uuid' ]
115 },
116 {
117 fields: [ 'channelId' ]
118 },
119 {
120 fields: [ 'id', 'privacy', 'state', 'waitTranscoding' ]
121 },
122 {
123 fields: [ 'url'],
124 unique: true
125 }
126]
127
97export enum ScopeNames { 128export enum ScopeNames {
98 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', 129 AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST',
99 WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', 130 WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS',
@@ -309,36 +340,7 @@ export enum ScopeNames {
309}) 340})
310@Table({ 341@Table({
311 tableName: 'video', 342 tableName: 'video',
312 indexes: [ 343 indexes
313 {
314 fields: [ 'name' ]
315 },
316 {
317 fields: [ 'createdAt' ]
318 },
319 {
320 fields: [ 'duration' ]
321 },
322 {
323 fields: [ 'views' ]
324 },
325 {
326 fields: [ 'likes' ]
327 },
328 {
329 fields: [ 'uuid' ]
330 },
331 {
332 fields: [ 'channelId' ]
333 },
334 {
335 fields: [ 'id', 'privacy', 'state', 'waitTranscoding' ]
336 },
337 {
338 fields: [ 'url'],
339 unique: true
340 }
341 ]
342}) 344})
343export class VideoModel extends Model<VideoModel> { 345export class VideoModel extends Model<VideoModel> {
344 346
@@ -794,33 +796,13 @@ export class VideoModel extends Model<VideoModel> {
794 796
795 static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string, hideNSFW: boolean) { 797 static async searchAndPopulateAccountAndServer (value: string, start: number, count: number, sort: string, hideNSFW: boolean) {
796 const query: IFindOptions<VideoModel> = { 798 const query: IFindOptions<VideoModel> = {
799 attributes: {
800 include: [ createSimilarityAttribute('VideoModel.name', value) ]
801 },
797 offset: start, 802 offset: start,
798 limit: count, 803 limit: count,
799 order: getSort(sort), 804 order: getSort(sort),
800 where: { 805 where: createSearchTrigramQuery('VideoModel.name', value)
801 [Sequelize.Op.or]: [
802 {
803 name: {
804 [ Sequelize.Op.iLike ]: '%' + value + '%'
805 }
806 },
807 {
808 preferredUsernameChannel: Sequelize.where(Sequelize.col('VideoChannel->Actor.preferredUsername'), {
809 [ Sequelize.Op.iLike ]: '%' + value + '%'
810 })
811 },
812 {
813 preferredUsernameAccount: Sequelize.where(Sequelize.col('VideoChannel->Account->Actor.preferredUsername'), {
814 [ Sequelize.Op.iLike ]: '%' + value + '%'
815 })
816 },
817 {
818 host: Sequelize.where(Sequelize.col('VideoChannel->Account->Actor->Server.host'), {
819 [ Sequelize.Op.iLike ]: '%' + value + '%'
820 })
821 }
822 ]
823 }
824 } 806 }
825 807
826 const serverActor = await getServerActor() 808 const serverActor = await getServerActor()