Boost scores in brower language
This commit is contained in:
parent
e586067521
commit
c37b360635
|
@ -426,8 +426,9 @@
|
||||||
import { EnhancedVideoChannel } from '../../../server/types/channel.model'
|
import { EnhancedVideoChannel } from '../../../server/types/channel.model'
|
||||||
import VueTagsInput from '@johmun/vue-tags-input'
|
import VueTagsInput from '@johmun/vue-tags-input'
|
||||||
import Pagination from '../components/Pagination.vue'
|
import Pagination from '../components/Pagination.vue'
|
||||||
import { VideosSearchQuery, VideoChannelsSearchQuery, ResultList } from '../../../PeerTube/shared/models'
|
import { VideoChannelsSearchQuery, ResultList } from '../../../PeerTube/shared/models'
|
||||||
import Nprogress from 'nprogress'
|
import Nprogress from 'nprogress'
|
||||||
|
import { VideosSearchQuery } from 'server/types/video-search.model'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
|
@ -632,6 +633,20 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
boostLanguagesQuery () {
|
||||||
|
const languages = new Set<string>()
|
||||||
|
|
||||||
|
for (const completeLanguage of navigator.languages) {
|
||||||
|
const language = completeLanguage.split('-')[0]
|
||||||
|
|
||||||
|
if (this.videoLanguages.find(vl => vl.id === language)) {
|
||||||
|
languages.add(language)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Array.from(languages)
|
||||||
|
},
|
||||||
|
|
||||||
homeTitleMessage () {
|
homeTitleMessage () {
|
||||||
return this.$gettext('Display homepage')
|
return this.$gettext('Display homepage')
|
||||||
}
|
}
|
||||||
|
@ -763,6 +778,8 @@
|
||||||
const { durationMin, durationMax } = durationRangeToAPIParams(this.formDurationRange)
|
const { durationMin, durationMax } = durationRangeToAPIParams(this.formDurationRange)
|
||||||
const { startDate, endDate } = publishedDateRangeToAPIParams(this.formPublishedDateRange)
|
const { startDate, endDate } = publishedDateRangeToAPIParams(this.formPublishedDateRange)
|
||||||
|
|
||||||
|
const boostLanguages = this.boostLanguagesQuery
|
||||||
|
|
||||||
return {
|
return {
|
||||||
search: this.formSearch,
|
search: this.formSearch,
|
||||||
|
|
||||||
|
@ -772,6 +789,8 @@
|
||||||
startDate,
|
startDate,
|
||||||
endDate,
|
endDate,
|
||||||
|
|
||||||
|
boostLanguages,
|
||||||
|
|
||||||
nsfw: this.formNSFW || false,
|
nsfw: this.formNSFW || false,
|
||||||
|
|
||||||
categoryOneOf: this.formCategoryOneOf ? [ this.formCategoryOneOf ] : undefined,
|
categoryOneOf: this.formCategoryOneOf ? [ this.formCategoryOneOf ] : undefined,
|
||||||
|
|
|
@ -45,6 +45,11 @@ instances-index:
|
||||||
enabled: false
|
enabled: false
|
||||||
hosts: null
|
hosts: null
|
||||||
|
|
||||||
|
videos-search:
|
||||||
|
# Allow client to send browser language to boost results score that are in these languages
|
||||||
|
boost-languages:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
api:
|
api:
|
||||||
# Blacklist hosts that will not be returned by the search API
|
# Blacklist hosts that will not be returned by the search API
|
||||||
blacklist:
|
blacklist:
|
||||||
|
|
|
@ -8,6 +8,10 @@ search-instance:
|
||||||
search_image: '/theme/framasoft/img/sepia-search.svg'
|
search_image: '/theme/framasoft/img/sepia-search.svg'
|
||||||
theme: 'framasoft'
|
theme: 'framasoft'
|
||||||
|
|
||||||
|
videos-search:
|
||||||
|
boost-languages:
|
||||||
|
enabled: true
|
||||||
|
|
||||||
instances-index:
|
instances-index:
|
||||||
whitelist:
|
whitelist:
|
||||||
enabled: true
|
enabled: true
|
||||||
|
@ -19,6 +23,11 @@ instances-index:
|
||||||
- 'aperi.tube'
|
- 'aperi.tube'
|
||||||
- 'peertube.datagueule.tv'
|
- 'peertube.datagueule.tv'
|
||||||
- 'thinkerview.video'
|
- 'thinkerview.video'
|
||||||
|
- 'replay.jres.org'
|
||||||
|
- 'tube.nah.re'
|
||||||
|
- 'peertube.parleur.net'
|
||||||
|
- 'video.passageenseine.fr'
|
||||||
|
- 'peertube.su'
|
||||||
|
|
||||||
api:
|
api:
|
||||||
blacklist:
|
blacklist:
|
||||||
|
|
|
@ -31,6 +31,11 @@ const CONFIG = {
|
||||||
LEGAL_NOTICES_URL: config.get<string>('search-instance.legal_notices_url'),
|
LEGAL_NOTICES_URL: config.get<string>('search-instance.legal_notices_url'),
|
||||||
THEME: config.get<string>('search-instance.theme')
|
THEME: config.get<string>('search-instance.theme')
|
||||||
},
|
},
|
||||||
|
VIDEOS_SEARCH: {
|
||||||
|
BOOST_LANGUAGES: {
|
||||||
|
ENABLED: config.get<boolean>('videos-search.boost-languages.enabled')
|
||||||
|
}
|
||||||
|
},
|
||||||
INSTANCES_INDEX: {
|
INSTANCES_INDEX: {
|
||||||
URL: config.get<string>('instances-index.url'),
|
URL: config.get<string>('instances-index.url'),
|
||||||
PUBLIC_URL: config.get<string>('instances-index.public_url'),
|
PUBLIC_URL: config.get<string>('instances-index.public_url'),
|
||||||
|
@ -72,7 +77,8 @@ const REQUESTS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const ELASTIC_SEARCH_QUERY = {
|
const ELASTIC_SEARCH_QUERY = {
|
||||||
FUZZINESS: 'AUTO:4,7'
|
FUZZINESS: 'AUTO:4,7',
|
||||||
|
BOOST_LANGUAGE_VALUE: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
function getWebserverUrl () {
|
function getWebserverUrl () {
|
||||||
|
|
|
@ -259,8 +259,45 @@ async function queryVideos (search: VideosSearchQuery) {
|
||||||
const body = {
|
const body = {
|
||||||
from: search.start,
|
from: search.start,
|
||||||
size: search.count,
|
size: search.count,
|
||||||
sort: buildSort(search.sort),
|
sort: buildSort(search.sort)
|
||||||
query: { bool }
|
}
|
||||||
|
|
||||||
|
// Allow to boost results depending on query languages
|
||||||
|
if (
|
||||||
|
CONFIG.VIDEOS_SEARCH.BOOST_LANGUAGES.ENABLED &&
|
||||||
|
Array.isArray(search.boostLanguages) &&
|
||||||
|
search.boostLanguages.length !== 0
|
||||||
|
) {
|
||||||
|
const boostScript = `
|
||||||
|
if (doc['language.id'].size() == 0) {
|
||||||
|
return _score;
|
||||||
|
}
|
||||||
|
|
||||||
|
String language = doc['language.id'].value;
|
||||||
|
|
||||||
|
for (String docLang: params.boostLanguages) {
|
||||||
|
if (docLang == language) return _score * params.boost;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _score;
|
||||||
|
`
|
||||||
|
|
||||||
|
Object.assign(body, {
|
||||||
|
query: {
|
||||||
|
script_score: {
|
||||||
|
query: { bool },
|
||||||
|
script: {
|
||||||
|
source: boostScript,
|
||||||
|
params: {
|
||||||
|
boostLanguages: search.boostLanguages,
|
||||||
|
boost: ELASTIC_SEARCH_QUERY.BOOST_LANGUAGE_VALUE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Object.assign(body, { query: { bool } })
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug({ body }, 'Will query Elastic Search for videos.')
|
logger.debug({ body }, 'Will query Elastic Search for videos.')
|
||||||
|
|
|
@ -68,6 +68,11 @@ const videosSearchValidator = [
|
||||||
check('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
|
check('durationMin').optional().isInt().withMessage('Should have a valid min duration'),
|
||||||
check('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
|
check('durationMax').optional().isInt().withMessage('Should have a valid max duration'),
|
||||||
|
|
||||||
|
check('boostLanguages')
|
||||||
|
.optional()
|
||||||
|
.customSanitizer(toArray)
|
||||||
|
.custom(isStringArray).withMessage('Should have a valid boostLanguages array'),
|
||||||
|
|
||||||
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
(req: express.Request, res: express.Response, next: express.NextFunction) => {
|
||||||
logger.debug({ query: req.query, body: req.body }, 'Checking videos search query')
|
logger.debug({ query: req.query, body: req.body }, 'Checking videos search query')
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { VideosSearchQuery as PeerTubeVideosSearchQuery} from '../../PeerTube/shared/models/search/videos-search-query.model'
|
import { VideosSearchQuery as PeerTubeVideosSearchQuery} from '../../PeerTube/shared/models/search/videos-search-query.model'
|
||||||
import { CommonSearch } from './common-search.model'
|
import { CommonSearch } from './common-search.model'
|
||||||
|
|
||||||
export type VideosSearchQuery = Omit<PeerTubeVideosSearchQuery, 'skipCount' | 'filter'> & CommonSearch
|
export type VideosSearchQuery = Omit<PeerTubeVideosSearchQuery, 'skipCount' | 'filter'> & CommonSearch & { boostLanguages: string[] }
|
||||||
|
|
Loading…
Reference in New Issue