Fix array filters
This commit is contained in:
parent
6a5563ed5b
commit
b8db45dca1
|
@ -16,9 +16,18 @@ export async function queryChannels (search: ChannelsSearchQuery) {
|
||||||
const filter: string[] = [ 'videosCount != 0' ]
|
const filter: string[] = [ 'videosCount != 0' ]
|
||||||
|
|
||||||
if (search.host) filter.push(`host = '${search.host}'`)
|
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.blockedAccounts && search.blockedAccounts.length !== 0) {
|
||||||
if (search.blockedHosts) filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
|
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.')
|
logger.debug({ filter }, 'Will query Meilisearch for channels.')
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,15 @@ export async function queryPlaylists (search: PlaylistsSearchQuery) {
|
||||||
]
|
]
|
||||||
|
|
||||||
if (search.host) filter.push(`ownerAccount.host = '${search.host}'`)
|
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)
|
if (search.uuids) addUUIDFilters(filter, search.uuids)
|
||||||
|
|
||||||
logger.debug({ filter }, 'Will query Meilisearch for playlists.')
|
logger.debug({ filter }, 'Will query Meilisearch for playlists.')
|
||||||
|
|
|
@ -12,8 +12,13 @@ import { formatActorForDB, formatActorSummaryForAPI } from './shared/meilisearch
|
||||||
export async function queryVideos (search: VideosSearchQuery) {
|
export async function queryVideos (search: VideosSearchQuery) {
|
||||||
const filter: string[] = []
|
const filter: string[] = []
|
||||||
|
|
||||||
if (search.blockedAccounts) filter.push(`account.handle NOT IN ${buildInValuesArray(search.blockedAccounts)}`)
|
if (search.blockedAccounts && search.blockedAccounts.length !== 0) {
|
||||||
if (search.blockedHosts) filter.push(`host NOT IN ${buildInValuesArray(search.blockedHosts)}`)
|
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.startDate) filter.push(`publishedAt >= ${new Date(search.startDate).getTime()}`)
|
||||||
if (search.endDate) filter.push(`publishedAt <= ${new Date(search.endDate).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()}`)
|
filter.push(`originallyPublishedAt <= ${new Date(search.originallyPublishedEndDate).getTime()}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (search.categoryOneOf) filter.push(`category.id IN ${buildInValuesArray(search.categoryOneOf)}`)
|
if (search.categoryOneOf && search.categoryOneOf.length !== 0) {
|
||||||
if (search.licenceOneOf) filter.push(`licence.id IN ${buildInValuesArray(search.licenceOneOf)}`)
|
filter.push(`category.id IN ${buildInValuesArray(search.categoryOneOf)}`)
|
||||||
if (search.languageOneOf) filter.push(`language.id IN ${buildInValuesArray(search.languageOneOf)}`)
|
}
|
||||||
|
|
||||||
|
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.durationMin) filter.push(`duration >= ${search.durationMin}`)
|
||||||
if (search.durationMax) filter.push(`duration <= ${search.durationMax}`)
|
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.host) filter.push(`account.host = '${search.host}'`)
|
||||||
if (search.uuids) addUUIDFilters(filter, search.uuids)
|
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())
|
const tagsOneOf = search.tagsOneOf.map(t => t.toLowerCase())
|
||||||
filter.push(`tags IN ${buildInValuesArray(tagsOneOf)}`)
|
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 tagsAllOf = search.tagsAllOf.map(t => t.toLowerCase())
|
||||||
const clause = tagsAllOf.map(tag => `tags = '${tag}'`).join(' AND ')
|
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.')
|
logger.debug({ filter }, 'Will query Meilisearch for videos.')
|
||||||
|
|
||||||
const boostLanguages = search.boostLanguages || []
|
if (search.boostLanguages && search.boostLanguages.length !== 0) {
|
||||||
boostLanguages.push('zxx') // No linguistic content
|
// 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, {
|
const result = await client.index(CONFIG.MEILISEARCH.INDEXES.VIDEOS).search(search.search, {
|
||||||
offset: search.start,
|
offset: search.start,
|
||||||
limit: search.count,
|
limit: search.count,
|
||||||
sort: buildSort(search.sort),
|
sort: buildSort(search.sort),
|
||||||
showRankingScore: true,
|
showRankingScore: true,
|
||||||
filter: [
|
filter
|
||||||
...filter,
|
|
||||||
|
|
||||||
`language.id IN ${buildInValuesArray(boostLanguages)} OR language.id IS NULL`
|
|
||||||
]
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return extractSearchQueryResult(result)
|
return extractSearchQueryResult(result)
|
||||||
|
|
Loading…
Reference in New Issue