Fix advanced search input with multiple tokens

This commit is contained in:
Chocobozzz 2024-10-07 08:46:39 +02:00
parent 0484b82fe3
commit 5f886402f5
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 13 additions and 8 deletions

View File

@ -155,25 +155,30 @@ export class AdvancedInputFilterComponent implements OnInit, AfterViewInit {
}
private addFilterToSearch (search: string, newFilter: AdvancedInputFilterChild) {
const prefix = newFilter.value.split(':').shift()
const filterTokens = this.restService.tokenizeString(newFilter.value)
let searchTokens = this.restService.tokenizeString(search)
// Tokenize search and remove a potential existing filter
const tokens = this.restService.tokenizeString(search)
.filter(t => !t.startsWith(prefix))
for (const filterToken of filterTokens) {
const prefix = filterToken.split(':').shift()
tokens.push(newFilter.value)
// Tokenize search and remove a potential existing filter
searchTokens = searchTokens.filter(t => !t.startsWith(prefix))
searchTokens.push(filterToken)
}
return tokens.join(' ')
return searchTokens.join(' ')
}
private parseFilters (search: string) {
const tokens = this.restService.tokenizeString(search)
const searchTokens = this.restService.tokenizeString(search)
this.enabledFilters = new Set()
for (const group of this.filters) {
for (const filter of group.children) {
if (tokens.includes(filter.value)) {
const filterTokens = this.restService.tokenizeString(filter.value)
if (filterTokens.every(filterToken => searchTokens.includes(filterToken))) {
this.enabledFilters.add(filter.value)
}
}