-import { intoArray } from '@app/helpers'
+import { splitIntoArray } from '@app/helpers'
import {
BooleanBothQuery,
BooleanQuery,
searchTarget: SearchTargetType
resultType: AdvancedSearchResultType
- // Filters we don't want to count, because they are mandatory
- private silentFilters = new Set([ 'sort', 'searchTarget' ])
-
constructor (options?: {
startDate?: string
endDate?: string
this.categoryOneOf = options.categoryOneOf || undefined
this.licenceOneOf = options.licenceOneOf || undefined
this.languageOneOf = options.languageOneOf || undefined
- this.tagsOneOf = intoArray(options.tagsOneOf)
- this.tagsAllOf = intoArray(options.tagsAllOf)
+ this.tagsOneOf = splitIntoArray(options.tagsOneOf)
+ this.tagsAllOf = splitIntoArray(options.tagsAllOf)
this.durationMin = options.durationMin ? parseInt(options.durationMin, 10) : undefined
this.durationMax = options.durationMax ? parseInt(options.durationMax, 10) : undefined
}
containsValues () {
- const obj = this.toUrlObject()
- for (const k of Object.keys(obj)) {
- if (this.silentFilters.has(k)) continue
-
- if (this.isValidValue(obj[k])) return true
- }
-
- return false
+ return this.size() !== 0
}
reset () {
originallyPublishedStartDate: this.originallyPublishedStartDate,
originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw,
- categoryOneOf: intoArray(this.categoryOneOf),
- licenceOneOf: intoArray(this.licenceOneOf),
- languageOneOf: intoArray(this.languageOneOf),
+ categoryOneOf: splitIntoArray(this.categoryOneOf),
+ licenceOneOf: splitIntoArray(this.licenceOneOf),
+ languageOneOf: splitIntoArray(this.languageOneOf),
tagsOneOf: this.tagsOneOf,
tagsAllOf: this.tagsAllOf,
durationMin: this.durationMin,
size () {
let acc = 0
- const obj = this.toUrlObject()
- for (const k of Object.keys(obj)) {
- if (this.silentFilters.has(k)) continue
+ if (this.isValidValue(this.startDate) || this.isValidValue(this.endDate)) acc++
+ if (this.isValidValue(this.originallyPublishedStartDate) || this.isValidValue(this.originallyPublishedEndDate)) acc++
- if (this.isValidValue(obj[k])) acc++
- }
+ if (this.isValidValue(this.nsfw)) acc++
+ if (this.isValidValue(this.categoryOneOf)) acc++
+ if (this.isValidValue(this.licenceOneOf)) acc++
+ if (this.isValidValue(this.languageOneOf)) acc++
+ if (this.isValidValue(this.tagsOneOf)) acc++
+ if (this.isValidValue(this.tagsAllOf)) acc++
+ if (this.isValidValue(this.durationMin) || this.isValidValue(this.durationMax)) acc++
+ if (this.isValidValue(this.isLive)) acc++
+ if (this.isValidValue(this.host)) acc++
+ if (this.isValidValue(this.resultType)) acc++
return acc
}
this.tagsAllOf !== undefined ||
this.durationMin !== undefined ||
this.durationMax !== undefined ||
- this.host !== undefined ||
this.isLive !== undefined
}
}