sepia-search-motore-di-rice.../server/initializers/constants.ts

240 lines
8.1 KiB
TypeScript
Raw Normal View History

2022-06-03 10:54:30 +02:00
import config from 'config'
2020-02-13 11:49:03 +01:00
import { isTestInstance } from '../helpers/core-utils'
const API_VERSION = 'v1'
const CONFIG = {
LISTEN: {
PORT: config.get<number>('listen.port')
},
2020-06-05 11:19:50 +02:00
WEBSERVER: {
SCHEME: config.get<boolean>('webserver.https') === true ? 'https' : 'http',
HOSTNAME: config.get<string>('webserver.hostname'),
PORT: config.get<number>('webserver.port')
},
2020-02-13 11:49:03 +01:00
ELASTIC_SEARCH: {
2021-02-03 11:49:26 +01:00
HTTP: config.get<string>('elastic-search.http'),
2021-02-04 08:55:02 +01:00
AUTH: {
USERNAME: config.get<string>('elastic-search.auth.username'),
PASSWORD: config.get<string>('elastic-search.auth.password')
},
2021-02-03 11:49:26 +01:00
SSL: {
CA: config.get<string>('elastic-search.ssl.ca')
},
2020-09-18 16:29:32 +02:00
HOSTNAME: config.get<string>('elastic-search.hostname'),
PORT: config.get<number>('elastic-search.port'),
2020-02-13 11:49:03 +01:00
INDEXES: {
2020-09-18 16:29:32 +02:00
VIDEOS: config.get<string>('elastic-search.indexes.videos'),
2021-06-24 15:18:54 +02:00
CHANNELS: config.get<string>('elastic-search.indexes.channels'),
PLAYLISTS: config.get<string>('elastic-search.indexes.playlists')
2020-02-13 11:49:03 +01:00
}
},
LOG: {
LEVEL: config.get<string>('log.level')
},
2020-08-27 14:44:21 +02:00
SEARCH_INSTANCE: {
2020-09-02 14:07:22 +02:00
NAME: config.get<string>('search-instance.name'),
2020-09-18 16:29:32 +02:00
NAME_IMAGE: config.get<string>('search-instance.name_image'),
SEARCH_IMAGE: config.get<string>('search-instance.search_image'),
2020-09-02 14:07:22 +02:00
DESCRIPTION: config.get<string>('search-instance.description'),
2020-09-18 16:29:32 +02:00
LEGAL_NOTICES_URL: config.get<string>('search-instance.legal_notices_url'),
THEME: config.get<string>('search-instance.theme')
2020-08-27 14:44:21 +02:00
},
2020-09-23 11:17:43 +02:00
VIDEOS_SEARCH: {
BOOST_LANGUAGES: {
ENABLED: config.get<boolean>('videos-search.boost-languages.enabled')
},
SEARCH_FIELDS: {
2022-11-24 17:04:53 +01:00
UUID: {
FIELD_NAME: 'uuid',
BOOST: config.get<number>('videos-search.search-fields.uuid.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.uuid.match_type')
},
SHORT_UUID: {
FIELD_NAME: 'shortUUID',
BOOST: config.get<number>('videos-search.search-fields.short-uuid.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.short-uuid.match_type')
},
NAME: {
FIELD_NAME: 'name',
BOOST: config.get<number>('videos-search.search-fields.name.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.name.match_type')
},
DESCRIPTION: {
FIELD_NAME: 'description',
BOOST: config.get<number>('videos-search.search-fields.description.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.description.match_type')
},
TAGS: {
FIELD_NAME: 'tags',
BOOST: config.get<number>('videos-search.search-fields.tags.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.tags.match_type')
},
ACCOUNT_DISPLAY_NAME: {
FIELD_NAME: 'account.displayName',
BOOST: config.get<number>('videos-search.search-fields.account-display-name.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.account-display-name.match_type')
},
CHANNEL_DISPLAY_NAME: {
FIELD_NAME: 'channel.displayName',
BOOST: config.get<number>('videos-search.search-fields.channel-display-name.boost'),
MATCH_TYPE: config.get<string>('videos-search.search-fields.channel-display-name.match_type')
}
}
},
CHANNELS_SEARCH: {
SEARCH_FIELDS: {
NAME: {
FIELD_NAME: 'name',
BOOST: config.get<number>('channels-search.search-fields.name.boost'),
MATCH_TYPE: config.get<string>('channels-search.search-fields.name.match_type')
},
DESCRIPTION: {
FIELD_NAME: 'description',
BOOST: config.get<number>('channels-search.search-fields.description.boost'),
MATCH_TYPE: config.get<string>('channels-search.search-fields.description.match_type')
},
DISPLAY_NAME: {
FIELD_NAME: 'displayName',
BOOST: config.get<number>('channels-search.search-fields.display-name.boost'),
MATCH_TYPE: config.get<string>('channels-search.search-fields.display-name.match_type')
},
ACCOUNT_DISPLAY_NAME: {
FIELD_NAME: 'ownerAccount.displayName',
BOOST: config.get<number>('channels-search.search-fields.account-display-name.boost'),
MATCH_TYPE: config.get<string>('channels-search.search-fields.account-display-name.match_type')
}
2020-09-23 11:17:43 +02:00
}
},
2021-06-24 15:18:54 +02:00
PLAYLISTS_SEARCH: {
SEARCH_FIELDS: {
2022-11-24 17:04:53 +01:00
UUID: {
FIELD_NAME: 'uuid',
BOOST: config.get<number>('playlists-search.search-fields.uuid.boost'),
MATCH_TYPE: config.get<string>('playlists-search.search-fields.uuid.match_type')
},
SHORT_UUID: {
FIELD_NAME: 'shortUUID',
BOOST: config.get<number>('playlists-search.search-fields.short-uuid.boost'),
MATCH_TYPE: config.get<string>('playlists-search.search-fields.short-uuid.match_type')
},
2021-06-24 16:53:43 +02:00
DISPLAY_NAME: {
FIELD_NAME: 'displayName',
BOOST: config.get<number>('playlists-search.search-fields.display-name.boost'),
MATCH_TYPE: config.get<string>('playlists-search.search-fields.display-name.match_type')
2021-06-24 15:18:54 +02:00
},
DESCRIPTION: {
FIELD_NAME: 'description',
BOOST: config.get<number>('playlists-search.search-fields.description.boost'),
MATCH_TYPE: config.get<string>('playlists-search.search-fields.description.match_type')
2021-06-24 15:18:54 +02:00
}
}
},
2020-02-14 14:09:31 +01:00
INSTANCES_INDEX: {
2020-06-11 11:04:00 +02:00
URL: config.get<string>('instances-index.url'),
2020-09-02 10:17:50 +02:00
PUBLIC_URL: config.get<string>('instances-index.public_url'),
2020-06-11 11:04:00 +02:00
WHITELIST: {
ENABLED: config.get<boolean>('instances-index.whitelist.enabled'),
HOSTS: config.get<string[]>('instances-index.whitelist.hosts')
}
2020-05-28 15:00:37 +02:00
},
2020-06-11 11:04:00 +02:00
API: {
BLACKLIST: {
ENABLED: config.get<boolean>('api.blacklist.enabled'),
HOSTS: config.get<string[]>('api.blacklist.hosts')
}
2020-02-13 11:49:03 +01:00
}
}
const SORTABLE_COLUMNS = {
2020-05-29 09:28:48 +02:00
VIDEOS_SEARCH: [ 'name', 'duration', 'createdAt', 'publishedAt', 'originallyPublishedAt', 'views', 'likes', 'match' ],
2021-06-24 15:18:54 +02:00
CHANNELS_SEARCH: [ 'match', 'displayName', 'createdAt' ],
PLAYLISTS_SEARCH: [ 'match', 'displayName', 'createdAt' ]
2020-02-13 11:49:03 +01:00
}
2021-08-02 16:16:27 +02:00
const PAGINATION_START = {
MAX: 9000
}
2021-08-02 15:54:29 +02:00
const PAGINATION_COUNT = {
DEFAULT: 20,
MAX: 500
}
2020-02-13 11:49:03 +01:00
2020-02-13 16:06:52 +01:00
const SCHEDULER_INTERVALS_MS = {
2021-06-24 16:53:43 +02:00
indexation: 60000 * 60 * 24 // 24 hours
2020-02-13 16:06:52 +01:00
}
2021-06-24 15:18:54 +02:00
const INDEXER_COUNT = 10
const INDEXER_LIMIT = 500000
2020-02-13 11:49:03 +01:00
2021-06-24 16:53:43 +02:00
const INDEXER_HOST_CONCURRENCY = 3
2020-03-04 15:32:39 +01:00
const INDEXER_QUEUE_CONCURRENCY = 3
const REQUESTS = {
MAX_RETRIES: 10,
WAIT: 10000 // 10 seconds
}
2020-09-23 10:35:23 +02:00
const ELASTIC_SEARCH_QUERY = {
2020-09-23 11:17:43 +02:00
FUZZINESS: 'AUTO:4,7',
OPERATOR: 'OR',
2021-11-24 13:36:50 +01:00
MINIMUM_SHOULD_MATCH: '3<75%',
2021-11-23 17:07:59 +01:00
BOOST_LANGUAGE_VALUE: 1,
MALUS_LANGUAGE_VALUE: 0.5,
VIDEOS_MULTI_MATCH_FIELDS: buildMatchFieldConfig(CONFIG.VIDEOS_SEARCH.SEARCH_FIELDS),
CHANNELS_MULTI_MATCH_FIELDS: buildMatchFieldConfig(CONFIG.CHANNELS_SEARCH.SEARCH_FIELDS),
PLAYLISTS_MULTI_MATCH_FIELDS: buildMatchFieldConfig(CONFIG.PLAYLISTS_SEARCH.SEARCH_FIELDS)
2020-09-23 10:35:23 +02:00
}
2020-09-02 16:24:25 +02:00
function getWebserverUrl () {
if (CONFIG.WEBSERVER.PORT === 80 || CONFIG.WEBSERVER.PORT === 443) {
return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME
}
return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
}
function buildMatchFieldConfig (fields: { [name: string]: { BOOST: number, FIELD_NAME: string, MATCH_TYPE: string } }) {
const selectFields = (matchType: 'phrase' | 'default') => {
return Object.keys(fields)
.filter(fieldName => fields[fieldName].MATCH_TYPE === matchType)
.map(fieldName => fields[fieldName])
}
const buildMultiMatch = (fields: { BOOST: number, FIELD_NAME: string }[]) => {
return fields.map(fieldObj => {
if (fieldObj.BOOST <= 0) return ''
return `${fieldObj.FIELD_NAME}^${fieldObj.BOOST}`
})
.filter(v => !!v)
}
return {
default: buildMultiMatch(selectFields('default')),
phrase: buildMultiMatch(selectFields('phrase'))
}
}
2020-02-13 11:49:03 +01:00
if (isTestInstance()) {
2021-06-24 16:53:43 +02:00
SCHEDULER_INTERVALS_MS.indexation = 1000 * 60 * 5 // 5 minutes
2020-02-13 11:49:03 +01:00
}
export {
2020-09-02 16:24:25 +02:00
getWebserverUrl,
2020-02-13 11:49:03 +01:00
CONFIG,
API_VERSION,
2021-08-02 15:54:29 +02:00
PAGINATION_COUNT,
2021-08-02 16:16:27 +02:00
PAGINATION_START,
2020-02-13 11:49:03 +01:00
SORTABLE_COLUMNS,
2020-03-04 15:32:39 +01:00
INDEXER_QUEUE_CONCURRENCY,
2020-02-13 16:06:52 +01:00
SCHEDULER_INTERVALS_MS,
2021-06-24 16:53:43 +02:00
INDEXER_HOST_CONCURRENCY,
2020-03-04 15:32:39 +01:00
INDEXER_COUNT,
2021-06-24 15:18:54 +02:00
INDEXER_LIMIT,
2020-09-23 10:35:23 +02:00
REQUESTS,
ELASTIC_SEARCH_QUERY
2020-02-13 11:49:03 +01:00
}