+import { SearchTargetType } from '@shared/models/search/search-target-query.model'
import { NSFWQuery } from '../../../../shared/models/search'
export class AdvancedSearch {
sort: string
+ searchTarget: SearchTargetType
+
+ // Filters we don't want to count, because they are mandatory
+ private silentFilters = new Set([ 'sort', 'searchTarget' ])
+
constructor (options?: {
startDate?: string
endDate?: string
durationMin?: string
durationMax?: string
sort?: string
+ searchTarget?: SearchTargetType
}) {
if (!options) return
this.durationMin = parseInt(options.durationMin, 10)
this.durationMax = parseInt(options.durationMax, 10)
+ this.searchTarget = options.searchTarget || undefined
+
if (isNaN(this.durationMin)) this.durationMin = undefined
if (isNaN(this.durationMax)) this.durationMax = undefined
}
containsValues () {
+ const exceptions = new Set([ 'sort', 'searchTarget' ])
+
const obj = this.toUrlObject()
for (const k of Object.keys(obj)) {
- if (k === 'sort') continue // Exception
+ if (this.silentFilters.has(k)) continue
if (obj[k] !== undefined && obj[k] !== '') return true
}
tagsAllOf: this.tagsAllOf,
durationMin: this.durationMin,
durationMax: this.durationMax,
- sort: this.sort
+ sort: this.sort,
+ searchTarget: this.searchTarget
}
}
tagsAllOf: this.intoArray(this.tagsAllOf),
durationMin: this.durationMin,
durationMax: this.durationMax,
- sort: this.sort
+ sort: this.sort,
+ searchTarget: this.searchTarget
}
}
const obj = this.toUrlObject()
for (const k of Object.keys(obj)) {
- if (k === 'sort') continue // Exception
+ if (this.silentFilters.has(k)) continue
if (obj[k] !== undefined && obj[k] !== '') acc++
}