Allow searching specifically in title, album, and artist

This commit is contained in:
An Phan 2017-03-23 12:18:17 +08:00
parent f2db3bac89
commit 221579c6e7
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2

View file

@ -103,10 +103,28 @@ export default {
computed: {
filteredItems () {
// Allow searching specifically in title, album, and artist
const re = /in:(title|album|artist)/ig
const fields = []
const matches = this.q.match(re)
if (matches) {
this.q = this.q.replace(re, '').trim()
if (!this.q) {
return this.songRows
}
matches.forEach(match => {
let field = match.split(':')[1].toLowerCase()
if (field !== 'title') {
field = `${field}.name`
}
fields.push(`song.${field}`)
})
}
return filterBy(
this.songRows,
this.q,
'song.title', 'song.album.name', 'song.artist.name'
...(fields.length ? fields : ['song.title', 'song.album.name', 'song.artist.name'])
)
},