Add ability to customize searched fields
This commit is contained in:
parent
a478b5f893
commit
f76edea5f8
|
@ -50,6 +50,35 @@ videos-search:
|
|||
boost-languages:
|
||||
enabled: true
|
||||
|
||||
# Add ability to change videos search fields boost value
|
||||
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html for more information
|
||||
# If boost == 0, the field will not be part of the search
|
||||
search-fields:
|
||||
name:
|
||||
boost: 5
|
||||
description:
|
||||
boost: 1
|
||||
tags:
|
||||
boost: 3
|
||||
account-display-name:
|
||||
boost: 2
|
||||
channel-display-name:
|
||||
boost: 2
|
||||
|
||||
channels-search:
|
||||
# Add ability to change channels search fields boost value
|
||||
# See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html for more information
|
||||
# If boost == 0, the field will not be part of the search
|
||||
search-fields:
|
||||
name:
|
||||
boost: 5
|
||||
description:
|
||||
boost: 1
|
||||
display-name:
|
||||
boost: 3
|
||||
account-display-name:
|
||||
boost: 2
|
||||
|
||||
api:
|
||||
# Blacklist hosts that will not be returned by the search API
|
||||
blacklist:
|
||||
|
|
|
@ -34,6 +34,48 @@ const CONFIG = {
|
|||
VIDEOS_SEARCH: {
|
||||
BOOST_LANGUAGES: {
|
||||
ENABLED: config.get<boolean>('videos-search.boost-languages.enabled')
|
||||
},
|
||||
SEARCH_FIELDS: {
|
||||
NAME: {
|
||||
FIELD_NAME: 'name',
|
||||
BOOST: config.get<number>('videos-search.search-fields.name.boost')
|
||||
},
|
||||
DESCRIPTION: {
|
||||
FIELD_NAME: 'description',
|
||||
BOOST: config.get<number>('videos-search.search-fields.description.boost')
|
||||
},
|
||||
TAGS: {
|
||||
FIELD_NAME: 'tags',
|
||||
BOOST: config.get<number>('videos-search.search-fields.tags.boost')
|
||||
},
|
||||
ACCOUNT_DISPLAY_NAME: {
|
||||
FIELD_NAME: 'account.displayName',
|
||||
BOOST: config.get<number>('videos-search.search-fields.account-display-name.boost')
|
||||
},
|
||||
CHANNEL_DISPLAY_NAME: {
|
||||
FIELD_NAME: 'channel.displayName',
|
||||
BOOST: config.get<number>('videos-search.search-fields.channel-display-name.boost')
|
||||
}
|
||||
}
|
||||
},
|
||||
CHANNELS_SEARCH: {
|
||||
SEARCH_FIELDS: {
|
||||
NAME: {
|
||||
FIELD_NAME: 'name',
|
||||
BOOST: config.get<number>('channels-search.search-fields.name.boost')
|
||||
},
|
||||
DESCRIPTION: {
|
||||
FIELD_NAME: 'description',
|
||||
BOOST: config.get<number>('channels-search.search-fields.description.boost')
|
||||
},
|
||||
DISPLAY_NAME: {
|
||||
FIELD_NAME: 'displayName',
|
||||
BOOST: config.get<number>('channels-search.search-fields.display-name.boost')
|
||||
},
|
||||
ACCOUNT_DISPLAY_NAME: {
|
||||
FIELD_NAME: 'ownerAccount.displayName',
|
||||
BOOST: config.get<number>('channels-search.search-fields.account-display-name.boost')
|
||||
}
|
||||
}
|
||||
},
|
||||
INSTANCES_INDEX: {
|
||||
|
@ -78,7 +120,9 @@ const REQUESTS = {
|
|||
|
||||
const ELASTIC_SEARCH_QUERY = {
|
||||
FUZZINESS: 'AUTO:4,7',
|
||||
BOOST_LANGUAGE_VALUE: 2
|
||||
BOOST_LANGUAGE_VALUE: 2,
|
||||
VIDEOS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.VIDEOS_SEARCH.SEARCH_FIELDS),
|
||||
CHANNELS_MULTI_MATCH_FIELDS: buildMultiMatchFields(CONFIG.CHANNELS_SEARCH.SEARCH_FIELDS)
|
||||
}
|
||||
|
||||
function getWebserverUrl () {
|
||||
|
@ -89,6 +133,17 @@ function getWebserverUrl () {
|
|||
return CONFIG.WEBSERVER.SCHEME + '://' + CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
|
||||
}
|
||||
|
||||
function buildMultiMatchFields (fields: { [name: string]: { BOOST: number, FIELD_NAME: string } }) {
|
||||
return Object.keys(fields)
|
||||
.map(id => {
|
||||
const obj = fields[id]
|
||||
if (obj.BOOST <= 0) return ''
|
||||
|
||||
return `${obj.FIELD_NAME}^${obj.BOOST}`
|
||||
})
|
||||
.filter(v => !!v)
|
||||
}
|
||||
|
||||
if (isTestInstance()) {
|
||||
SCHEDULER_INTERVALS_MS.videosIndexer = 1000 * 60 * 5 // 5 minutes
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ async function queryChannels (search: ChannelsSearchQuery) {
|
|||
{
|
||||
multi_match: {
|
||||
query: search.search,
|
||||
fields: [ 'name^5', 'displayName^3', 'description' ],
|
||||
fields: ELASTIC_SEARCH_QUERY.CHANNELS_MULTI_MATCH_FIELDS,
|
||||
fuzziness: ELASTIC_SEARCH_QUERY.FUZZINESS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ async function queryVideos (search: VideosSearchQuery) {
|
|||
{
|
||||
multi_match: {
|
||||
query: search.search,
|
||||
fields: [ 'name^5', 'description', 'tags^3' ],
|
||||
fields: ELASTIC_SEARCH_QUERY.VIDEOS_MULTI_MATCH_FIELDS,
|
||||
fuzziness: ELASTIC_SEARCH_QUERY.FUZZINESS
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue