Fix array filters

This commit is contained in:
Chocobozzz 2024-01-15 11:12:00 +01:00
parent 6a5563ed5b
commit b8db45dca1
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 46 additions and 19 deletions

View File

@ -16,9 +16,18 @@ export async function queryChannels (search: ChannelsSearchQuery) {
const filter: string[] = [ 'videosCount != 0' ]
if (search.host) filter.push(`host = '${search.host}'`)
if (search.blockedAccounts) filter.push(`ownerAccount.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
if (search.handles) filter.push(`handle IN ${buildInValuesArray(search.handles)}`)
if (search.blockedHosts) filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
if (search.blockedAccounts && search.blockedAccounts.length !== 0) {
filter.push(`ownerAccount.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
}
if (search.handles && search.handles.length !== 0) {
filter.push(`handle IN ${buildInValuesArray(search.handles)}`)
}
if (search.blockedHosts && search.blockedHosts.length !== 0) {
filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
}
logger.debug({ filter }, 'Will query Meilisearch for channels.')

View File

@ -14,8 +14,15 @@ export async function queryPlaylists (search: PlaylistsSearchQuery) {
]
if (search.host) filter.push(`ownerAccount.host = '${search.host}'`)
if (search.blockedAccounts) filter.push(`ownerAccount.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
if (search.blockedHosts) filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
if (search.blockedAccounts && search.blockedAccounts.length !== 0) {
filter.push(`ownerAccount.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
}
if (search.blockedHosts && search.blockedHosts.length !== 0) {
filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
}
if (search.uuids) addUUIDFilters(filter, search.uuids)
logger.debug({ filter }, 'Will query Meilisearch for playlists.')

View File

@ -12,8 +12,13 @@ import { formatActorForDB, formatActorSummaryForAPI } from './shared/meilisearch
export async function queryVideos (search: VideosSearchQuery) {
const filter: string[] = []
if (search.blockedAccounts) filter.push(`account.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
if (search.blockedHosts) filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
if (search.blockedAccounts && search.blockedAccounts.length !== 0) {
filter.push(`account.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
}
if (search.blockedHosts && search.blockedHosts.length !== 0) {
filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
}
if (search.startDate) filter.push(`publishedAt >= ${new Date(search.startDate).getTime()}`)
if (search.endDate) filter.push(`publishedAt <= ${new Date(search.endDate).getTime()}`)
@ -25,9 +30,17 @@ export async function queryVideos (search: VideosSearchQuery) {
filter.push(`originallyPublishedAt <= ${new Date(search.originallyPublishedEndDate).getTime()}`)
}
if (search.categoryOneOf) filter.push(`category.id IN ${buildInValuesArray(search.categoryOneOf)}`)
if (search.licenceOneOf) filter.push(`licence.id IN ${buildInValuesArray(search.licenceOneOf)}`)
if (search.languageOneOf) filter.push(`language.id IN ${buildInValuesArray(search.languageOneOf)}`)
if (search.categoryOneOf && search.categoryOneOf.length !== 0) {
filter.push(`category.id IN ${buildInValuesArray(search.categoryOneOf)}`)
}
if (search.licenceOneOf && search.licenceOneOf.length !== 0) {
filter.push(`licence.id IN ${buildInValuesArray(search.licenceOneOf)}`)
}
if (search.languageOneOf && search.languageOneOf.length !== 0) {
filter.push(`language.id IN ${buildInValuesArray(search.languageOneOf)}`)
}
if (search.durationMin) filter.push(`duration >= ${search.durationMin}`)
if (search.durationMax) filter.push(`duration <= ${search.durationMax}`)
@ -38,12 +51,12 @@ export async function queryVideos (search: VideosSearchQuery) {
if (search.host) filter.push(`account.host = '${search.host}'`)
if (search.uuids) addUUIDFilters(filter, search.uuids)
if (search.tagsOneOf) {
if (search.tagsOneOf && search.tagsOneOf.length !== 0) {
const tagsOneOf = search.tagsOneOf.map(t => t.toLowerCase())
filter.push(`tags IN ${buildInValuesArray(tagsOneOf)}`)
}
if (search.tagsAllOf) {
if (search.tagsAllOf && search.tagsAllOf.length !== 0) {
const tagsAllOf = search.tagsAllOf.map(t => t.toLowerCase())
const clause = tagsAllOf.map(tag => `tags = '${tag}'`).join(' AND ')
@ -52,19 +65,17 @@ export async function queryVideos (search: VideosSearchQuery) {
logger.debug({ filter }, 'Will query Meilisearch for videos.')
const boostLanguages = search.boostLanguages || []
boostLanguages.push('zxx') // No linguistic content
if (search.boostLanguages && search.boostLanguages.length !== 0) {
// No linguistic content
filter.push(`language.id IN ${buildInValuesArray([ ...search.boostLanguages, 'zxx' ])} OR language.id IS NULL`)
}
const result = await client.index(CONFIG.MEILISEARCH.INDEXES.VIDEOS).search(search.search, {
offset: search.start,
limit: search.count,
sort: buildSort(search.sort),
showRankingScore: true,
filter: [
...filter,
`language.id IN ${buildInValuesArray(boostLanguages)} OR language.id IS NULL`
]
filter
})
return extractSearchQueryResult(result)