[web] Fix error when search queries contain banks or start with blanks.

This commit is contained in:
Alain Nussbaumer 2024-03-20 21:37:46 +01:00
parent bf8e433a0e
commit ec07729424
2 changed files with 27 additions and 41 deletions

View File

@ -311,17 +311,16 @@ export default {
methods: { methods: {
search(route) { search(route) {
if (!route.query.query || route.query.query === '') { this.search_query = route.query.query?.trim()
this.search_query = '' if (!this.search_query) {
this.$refs.search_field.focus() this.$refs.search_field.focus()
return return
} }
route.query.query = this.search_query
this.search_query = route.query.query
this.searchMusic(route.query) this.searchMusic(route.query)
this.searchAudiobooks(route.query) this.searchAudiobooks(route.query)
this.searchPodcasts(route.query) this.searchPodcasts(route.query)
this.$store.dispatch('add_recent_search', route.query.query) this.$store.dispatch('add_recent_search', this.search_query)
}, },
searchMusic(query) { searchMusic(query) {
@ -334,23 +333,19 @@ export default {
) { ) {
return return
} }
const searchParams = { const searchParams = {
type: query.type, type: query.type
media_kind: 'music'
} }
if (query.query.startsWith('query:')) { if (query.query.startsWith('query:')) {
searchParams.expression = query.query.replace(/^query:/u, '').trim() searchParams.expression = `${query.query.replace(/^query:/u, '').trim()} and media_kind is music`
} else { } else {
searchParams.query = query.query searchParams.query = query.query
searchParams.media_kind = 'music'
} }
if (query.limit) { if (query.limit) {
searchParams.limit = query.limit searchParams.limit = query.limit
searchParams.offset = query.offset searchParams.offset = query.offset
} }
webapi.search(searchParams).then(({ data }) => { webapi.search(searchParams).then(({ data }) => {
this.tracks = new GroupedList(data.tracks) this.tracks = new GroupedList(data.tracks)
this.artists = new GroupedList(data.artists) this.artists = new GroupedList(data.artists)
@ -364,24 +359,20 @@ export default {
if (query.type.indexOf('audiobook') < 0) { if (query.type.indexOf('audiobook') < 0) {
return return
} }
const parameters = {
const searchParams = { type: 'album'
type: 'album',
media_kind: 'audiobook'
} }
if (query.query.startsWith('query:')) { if (query.query.startsWith('query:')) {
searchParams.expression = query.query.replace(/^query:/u, '').trim() parameters.expression = query.query.replace(/^query:/u, '').trim()
} else { } else {
searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is audiobook)` parameters.expression = `album includes "${query.query}" or artist includes "${query.query}"`
} }
parameters.expression = `(${parameters.expression}) and media_kind is audiobook`
if (query.limit) { if (query.limit) {
searchParams.limit = query.limit parameters.limit = query.limit
searchParams.offset = query.offset parameters.offset = query.offset
} }
webapi.search(parameters).then(({ data }) => {
webapi.search(searchParams).then(({ data }) => {
this.audiobooks = new GroupedList(data.albums) this.audiobooks = new GroupedList(data.albums)
}) })
}, },
@ -390,24 +381,20 @@ export default {
if (query.type.indexOf('podcast') < 0) { if (query.type.indexOf('podcast') < 0) {
return return
} }
const parameters = {
const searchParams = { type: 'album'
type: 'album',
media_kind: 'podcast'
} }
if (query.query.startsWith('query:')) { if (query.query.startsWith('query:')) {
searchParams.expression = query.query.replace(/^query:/u, '').trim() parameters.expression = query.query.replace(/^query:/u, '').trim()
} else { } else {
searchParams.expression = `((album includes "${query.query}" or artist includes "${query.query}") and media_kind is podcast)` parameters.expression = `album includes "${query.query}" or artist includes "${query.query}"`
} }
parameters.expression = `(${parameters.expression}) and media_kind is podcast`
if (query.limit) { if (query.limit) {
searchParams.limit = query.limit parameters.limit = query.limit
searchParams.offset = query.offset parameters.offset = query.offset
} }
webapi.search(parameters).then(({ data }) => {
webapi.search(searchParams).then(({ data }) => {
this.podcasts = new GroupedList(data.albums) this.podcasts = new GroupedList(data.albums)
}) })
}, },

View File

@ -439,17 +439,16 @@ export default {
}, },
search() { search() {
this.reset() this.reset()
// If no search query present reset and focus search field this.search_query = this.query.query?.trim()
if ( if (
!this.query.query || !this.search_query ||
this.query.query === '' || this.search_query.startsWith('query:')
this.query.query.startsWith('query:')
) { ) {
this.search_query = '' this.search_query = ''
this.$refs.search_field.focus() this.$refs.search_field.focus()
return return
} }
this.search_query = this.query.query this.query.query = this.search_query
this.search_param.limit = this.query.limit ? this.query.limit : PAGE_SIZE this.search_param.limit = this.query.limit ? this.query.limit : PAGE_SIZE
this.search_param.offset = this.query.offset ? this.query.offset : 0 this.search_param.offset = this.query.offset ? this.query.offset : 0
this.$store.dispatch('add_recent_search', this.query.query) this.$store.dispatch('add_recent_search', this.query.query)