diff --git a/utils/search/search.go b/utils/search/search.go index 35f7a7bf..f1cb37b7 100644 --- a/utils/search/search.go +++ b/utils/search/search.go @@ -8,6 +8,8 @@ import ( "time" + "fmt" + "github.com/NyaaPantsu/nyaa/config" "github.com/NyaaPantsu/nyaa/models" "github.com/NyaaPantsu/nyaa/models/torrents" @@ -92,6 +94,7 @@ func byQuery(c *gin.Context, pagenum int, countAll bool, withUser bool, deleted return torrentParam, torrentCache.Torrents, torrentCache.Count, nil } totalHits, tor, err := torrentParam.Find(models.ElasticSearchClient) + fmt.Println("lol") cache.C.Set(torrentParam.Identifier(), &structs.TorrentCache{tor, int(totalHits)}, 5*time.Minute) // Convert back to non-json torrents return torrentParam, tor, int(totalHits), err @@ -109,6 +112,10 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool, search.Hidden = hidden search.Full = withUser + orderBy := search.Sort.ToDBField() + if search.Sort == structs.Date { + search.NotNull = search.Sort.ToDBField() + " IS NOT NULL" + } if found, ok := cache.C.Get(search.Identifier()); ok { torrentCache := found.(*structs.TorrentCache) tor = torrentCache.Torrents @@ -116,11 +123,6 @@ func byQueryPostgres(c *gin.Context, pagenum int, countAll bool, withUser bool, return } - orderBy := search.Sort.ToDBField() - if search.Sort == structs.Date { - search.NotNull = search.Sort.ToDBField() + " IS NOT NULL" - } - orderBy += " " switch search.Order { diff --git a/utils/search/structs/structs.go b/utils/search/structs/structs.go index 299eedfa..2f5d318d 100644 --- a/utils/search/structs/structs.go +++ b/utils/search/structs/structs.go @@ -54,7 +54,11 @@ type TorrentParam struct { } func (p *TorrentParam) Identifier() string { - return fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%d%d%v%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, p.Category, p.Full, p.Order, p.Hidden) + cats := "" + 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) } func (st *Status) ToString() string {