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

64 lines
1.6 KiB
TypeScript
Raw Normal View History

2023-11-13 10:06:43 +01:00
import { QueueObject } from 'async'
2021-06-24 15:18:54 +02:00
import { logger } from '../../helpers/logger'
import { AbstractIndexer, QueueParam } from './shared'
import { CONFIG, SORTABLE_COLUMNS } from '../../initializers/constants'
import { formatVideoForDB } from '../meilisearch/meilisearch-videos'
2021-06-24 15:18:54 +02:00
import { getVideo } from '../requests/peertube-instance'
import { DBVideo, IndexableVideo } from '../../types/video.model'
2021-06-24 15:18:54 +02:00
export class VideoIndexer extends AbstractIndexer <IndexableVideo, DBVideo> {
2023-11-13 10:06:43 +01:00
protected readonly indexQueue: QueueObject<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',
2023-11-13 11:01:17 +01:00
'searchableDescription'
]
protected readonly rankingRules = [
2024-01-15 11:23:14 +01:00
'words',
'typo',
'proximity',
'attribute',
'sort',
'exactness',
'language:asc',
'views:desc'
]
2021-06-24 15:18:54 +02:00
constructor () {
super(CONFIG.MEILISEARCH.INDEXES.VIDEOS, formatVideoForDB)
2021-06-24 15:18:54 +02:00
}
async indexSpecificElement (host: string, uuid: string) {
2024-01-04 14:20:20 +01:00
await this.waitForBulkIndexation()
2021-06-24 15:18:54 +02:00
const video = await getVideo(host, uuid)
logger.info('Indexing specific video %s of %s.', uuid, host)
2024-01-04 14:20:20 +01:00
this.addElementsToBulkIndex([ video ])
2021-07-28 13:25:39 +02:00
}
2021-06-24 15:18:54 +02:00
}