sepia-search-motore-di-rice.../server/lib/indexers/video-indexer.ts

62 lines
1.5 KiB
TypeScript

import { AsyncQueue } from 'async'
import { logger } from '../../helpers/logger'
import { AbstractIndexer, QueueParam } from './shared'
import { CONFIG, SORTABLE_COLUMNS } from '../../initializers/constants'
import { formatVideoForDB } from '../meilisearch/meilisearch-videos'
import { getVideo } from '../requests/peertube-instance'
import { DBVideo, IndexableVideo } from '../../types/video.model'
export class VideoIndexer extends AbstractIndexer <IndexableVideo, DBVideo> {
protected readonly indexQueue: AsyncQueue<QueueParam>
protected readonly primaryKey = 'uuid'
protected readonly filterableAttributes = [
'uuid',
'host',
'account.handle',
'account.host',
'publishedAt',
'originallyPublishedAt',
'nsfw',
'category.id',
'licence.id',
'language.id',
'tags',
'duration',
'isLive'
]
protected readonly sortableAttributes = SORTABLE_COLUMNS.VIDEOS_SEARCH
// Keep the order, most important first
protected readonly searchableAttributes = [
'name',
'tags',
'account.displayName',
'channel.displayName',
'description'
]
protected readonly rankingRules = [
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
'language:asc',
'views:desc'
]
constructor () {
super(CONFIG.MEILISEARCH.INDEXES.VIDEOS, formatVideoForDB)
}
async indexSpecificElement (host: string, uuid: string) {
const video = await getVideo(host, uuid)
logger.info('Indexing specific video %s of %s.', uuid, host)
return this.indexElements([ video ])
}
}