mirror of
https://github.com/navidrome/navidrome.git
synced 2025-06-09 11:52:35 +03:00
feat: search in WebUI now is more flexible, searching in all relevant fields in the current view
This commit is contained in:
parent
32fbf2e9eb
commit
8401d85f78
@ -24,6 +24,7 @@ func NewAlbumRepository(ctx context.Context, o orm.Ormer) model.AlbumRepository
|
|||||||
"artist": "compilation asc, album_artist asc, name asc",
|
"artist": "compilation asc, album_artist asc, name asc",
|
||||||
}
|
}
|
||||||
r.filterMappings = map[string]filterFunc{
|
r.filterMappings = map[string]filterFunc{
|
||||||
|
"name": fullTextFilter,
|
||||||
"compilation": booleanFilter,
|
"compilation": booleanFilter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ func NewArtistRepository(ctx context.Context, o orm.Ormer) model.ArtistRepositor
|
|||||||
r.ormer = o
|
r.ormer = o
|
||||||
r.indexGroups = utils.ParseIndexGroups(conf.Server.IndexGroups)
|
r.indexGroups = utils.ParseIndexGroups(conf.Server.IndexGroups)
|
||||||
r.tableName = "artist"
|
r.tableName = "artist"
|
||||||
|
r.filterMappings = map[string]filterFunc{
|
||||||
|
"name": fullTextFilter,
|
||||||
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ func NewMediaFileRepository(ctx context.Context, o orm.Ormer) *mediaFileReposito
|
|||||||
"artist": "artist asc, album asc, disc_number asc, track_number asc",
|
"artist": "artist asc, album asc, disc_number asc, track_number asc",
|
||||||
"album": "album asc, disc_number asc, track_number asc",
|
"album": "album asc, disc_number asc, track_number asc",
|
||||||
}
|
}
|
||||||
|
r.filterMappings = map[string]filterFunc{
|
||||||
|
"title": fullTextFilter,
|
||||||
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
"github.com/deluan/rest"
|
"github.com/deluan/rest"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
"github.com/kennygrant/sanitize"
|
||||||
)
|
)
|
||||||
|
|
||||||
type filterFunc = func(field string, value interface{}) Sqlizer
|
type filterFunc = func(field string, value interface{}) Sqlizer
|
||||||
@ -249,3 +250,17 @@ func booleanFilter(field string, value interface{}) Sqlizer {
|
|||||||
v := strings.ToLower(value.(string))
|
v := strings.ToLower(value.(string))
|
||||||
return Eq{field: strings.ToLower(v) == "true"}
|
return Eq{field: strings.ToLower(v) == "true"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fullTextFilter(field string, value interface{}) Sqlizer {
|
||||||
|
q := value.(string)
|
||||||
|
q = strings.TrimSpace(sanitize.Accents(strings.ToLower(strings.TrimSuffix(q, "*"))))
|
||||||
|
parts := strings.Split(q, " ")
|
||||||
|
filters := And{}
|
||||||
|
for _, part := range parts {
|
||||||
|
filters = append(filters, Or{
|
||||||
|
Like{"full_text": part + "%"},
|
||||||
|
Like{"full_text": "%" + part + "%"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return filters
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
NumberField,
|
NumberField,
|
||||||
FunctionField,
|
FunctionField,
|
||||||
SearchInput,
|
SearchInput,
|
||||||
TextInput,
|
NumberInput,
|
||||||
Show,
|
Show,
|
||||||
SimpleShowLayout,
|
SimpleShowLayout,
|
||||||
TextField
|
TextField
|
||||||
@ -19,7 +19,7 @@ import { useMediaQuery } from '@material-ui/core'
|
|||||||
const AlbumFilter = (props) => (
|
const AlbumFilter = (props) => (
|
||||||
<Filter {...props}>
|
<Filter {...props}>
|
||||||
<SearchInput source="name" alwaysOn />
|
<SearchInput source="name" alwaysOn />
|
||||||
<TextInput source="artist" />
|
<NumberInput source="year" />
|
||||||
</Filter>
|
</Filter>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -9,8 +9,7 @@ import {
|
|||||||
SearchInput,
|
SearchInput,
|
||||||
Show,
|
Show,
|
||||||
SimpleShowLayout,
|
SimpleShowLayout,
|
||||||
TextField,
|
TextField
|
||||||
TextInput
|
|
||||||
} from 'react-admin'
|
} from 'react-admin'
|
||||||
import { useMediaQuery } from '@material-ui/core'
|
import { useMediaQuery } from '@material-ui/core'
|
||||||
import {
|
import {
|
||||||
@ -29,8 +28,6 @@ import { SongBulkActions } from './SongBulkActions'
|
|||||||
const SongFilter = (props) => (
|
const SongFilter = (props) => (
|
||||||
<Filter {...props}>
|
<Filter {...props}>
|
||||||
<SearchInput source="title" alwaysOn />
|
<SearchInput source="title" alwaysOn />
|
||||||
<TextInput source="album" />
|
|
||||||
<TextInput source="artist" />
|
|
||||||
</Filter>
|
</Filter>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user