Added search for languages back end
Cette révision appartient à :
Parent
bef7a2ed3d
révision
fce83bcdb9
4 fichiers modifiés avec 38 ajouts et 13 suppressions
|
@ -151,6 +151,17 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
|
|||
}
|
||||
conditions = append(conditions, strings.Join(conditionsOr, " OR "))
|
||||
}
|
||||
if len(search.Languages) > 0 {
|
||||
langs := ""
|
||||
for key, val := range search.Languages {
|
||||
langs += val.Code
|
||||
if key+1 < len(search.Languages) {
|
||||
langs += ","
|
||||
}
|
||||
}
|
||||
conditions = append(conditions, "language "+searchOperator)
|
||||
parameters.Params = append(parameters.Params, "%"+langs+"%")
|
||||
}
|
||||
|
||||
if search.UserID != 0 {
|
||||
conditions = append(conditions, "uploader = ?")
|
||||
|
@ -183,10 +194,6 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool,
|
|||
if len(search.NotNull) > 0 {
|
||||
conditions = append(conditions, search.NotNull)
|
||||
}
|
||||
if search.Language != "" {
|
||||
conditions = append(conditions, "language "+searchOperator)
|
||||
parameters.Params = append(parameters.Params, "%"+search.Language+"%")
|
||||
}
|
||||
if search.MinSize > 0 {
|
||||
conditions = append(conditions, "filesize >= ?")
|
||||
parameters.Params = append(parameters.Params, uint64(search.MinSize))
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
catUtil "github.com/NyaaPantsu/nyaa/utils/categories"
|
||||
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -48,7 +49,7 @@ type TorrentParam struct {
|
|||
ToDate DateFilter
|
||||
NotNull string // csv
|
||||
NameLike string // csv
|
||||
Language string
|
||||
Languages publicSettings.Languages
|
||||
MinSize SizeBytes
|
||||
MaxSize SizeBytes
|
||||
}
|
||||
|
@ -58,7 +59,11 @@ func (p *TorrentParam) Identifier() string {
|
|||
for _, v := range p.Category {
|
||||
cats += fmt.Sprintf("%d%d", v.Main, v.Sub)
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%s%t%t%t", p.NameLike, p.NotNull, p.Language, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, p.FromDate, p.ToDate, p.UserID, p.TorrentID, cats, p.Full, p.Order, p.Hidden)
|
||||
languages := ""
|
||||
for _, v := range p.Languages {
|
||||
languages += fmt.Sprintf("%s%s", v.Code, v.Name)
|
||||
}
|
||||
return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%s%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, p.FromDate, p.ToDate, p.UserID, p.TorrentID, cats, p.Full, p.Order, p.Hidden)
|
||||
}
|
||||
|
||||
func (st *Status) ToString() string {
|
||||
|
@ -189,8 +194,7 @@ func (c Category) IsSubSet() bool {
|
|||
return c.Sub != 0
|
||||
}
|
||||
|
||||
// Parse sets category by string
|
||||
// returns true if string is valid otherwise returns false
|
||||
// ParseCategories sets category by string
|
||||
func ParseCategories(s string) []*Category {
|
||||
if s != "" {
|
||||
parts := strings.Split(s, ",")
|
||||
|
@ -220,6 +224,18 @@ func ParseCategories(s string) []*Category {
|
|||
return Categories{}
|
||||
}
|
||||
|
||||
// ParseLanguages sets languages by string
|
||||
func ParseLanguages(s string) publicSettings.Languages {
|
||||
var languages publicSettings.Languages
|
||||
if s != "" {
|
||||
parts := strings.Split(s, ",")
|
||||
for _, lang := range parts {
|
||||
languages = append(languages, publicSettings.Language{Name: "", Code: lang}) // We just need the code
|
||||
}
|
||||
}
|
||||
return languages
|
||||
}
|
||||
|
||||
func (sz *SizeBytes) Parse(s string, sizeType string) bool {
|
||||
if s == "" {
|
||||
*sz = 0
|
||||
|
|
|
@ -73,7 +73,7 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
ascending = true
|
||||
}
|
||||
|
||||
language := strings.TrimSpace(c.Query("lang"))
|
||||
language := ParseLanguages(c.Query("lang"))
|
||||
|
||||
p.NameLike = nameLike
|
||||
p.Max = uint32(max)
|
||||
|
@ -82,7 +82,7 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
p.Status = status
|
||||
p.Sort = sortMode
|
||||
p.Category = categories
|
||||
p.Language = language
|
||||
p.Languages = language
|
||||
p.FromDate = fromDate
|
||||
p.ToDate = toDate
|
||||
p.MinSize = minSize
|
||||
|
@ -152,8 +152,10 @@ func (p *TorrentParam) ToFilterQuery() string {
|
|||
query += " filesize: [* " + sMaxSize + "]"
|
||||
}
|
||||
|
||||
if p.Language != "" {
|
||||
query += " language:" + p.Language
|
||||
if len(p.Languages) > 0{
|
||||
for _, val := range p.Languages {
|
||||
query += " language: " + val.Code
|
||||
}
|
||||
}
|
||||
|
||||
return query
|
||||
|
@ -237,7 +239,7 @@ func (p *TorrentParam) Clone() TorrentParam {
|
|||
ToDate: p.ToDate,
|
||||
NotNull: p.NotNull,
|
||||
NameLike: p.NameLike,
|
||||
Language: p.Language,
|
||||
Languages: p.Languages,
|
||||
MinSize: p.MinSize,
|
||||
MaxSize: p.MaxSize,
|
||||
}
|
Référencer dans un nouveau ticket