Merge pull request #881 from NyaaPantsu/new-search-date-filter
Field Date Filter
Cette révision appartient à :
révision
3afde2e3c1
3 fichiers modifiés avec 43 ajouts et 0 suppressions
|
@ -162,6 +162,8 @@ type SearchParam struct {
|
||||||
Status Status
|
Status Status
|
||||||
Sort SortMode
|
Sort SortMode
|
||||||
Category Category
|
Category Category
|
||||||
|
FromDate string
|
||||||
|
ToDate string
|
||||||
Page int
|
Page int
|
||||||
UserID uint
|
UserID uint
|
||||||
Max uint
|
Max uint
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
elastic "gopkg.in/olivere/elastic.v5"
|
elastic "gopkg.in/olivere/elastic.v5"
|
||||||
|
@ -29,6 +30,8 @@ type TorrentParam struct {
|
||||||
UserID uint32
|
UserID uint32
|
||||||
TorrentID uint32
|
TorrentID uint32
|
||||||
FromID uint32
|
FromID uint32
|
||||||
|
FromDate string
|
||||||
|
ToDate string
|
||||||
NotNull string // csv
|
NotNull string // csv
|
||||||
Null string // csv
|
Null string // csv
|
||||||
NameLike string // csv
|
NameLike string // csv
|
||||||
|
@ -69,6 +72,14 @@ func (p *TorrentParam) FromRequest(r *http.Request) {
|
||||||
var status Status
|
var status Status
|
||||||
status.Parse(r.URL.Query().Get("s"))
|
status.Parse(r.URL.Query().Get("s"))
|
||||||
|
|
||||||
|
maxage, err := strconv.Atoi(r.URL.Query().Get("maxage"))
|
||||||
|
if err != nil {
|
||||||
|
p.FromDate = r.URL.Query().Get("fromDate")
|
||||||
|
p.ToDate = r.URL.Query().Get("toDate")
|
||||||
|
} else {
|
||||||
|
p.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02")
|
||||||
|
}
|
||||||
|
|
||||||
var category Category
|
var category Category
|
||||||
category.Parse(r.URL.Query().Get("c"))
|
category.Parse(r.URL.Query().Get("c"))
|
||||||
|
|
||||||
|
@ -129,6 +140,15 @@ func (p *TorrentParam) ToFilterQuery() string {
|
||||||
if p.FromID != 0 {
|
if p.FromID != 0 {
|
||||||
query += " id:>" + strconv.FormatInt(int64(p.FromID), 10)
|
query += " id:>" + strconv.FormatInt(int64(p.FromID), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if p.FromDate != "" && p.ToDate != "" {
|
||||||
|
query += " date: [" + p.FromDate + " " + p.ToDate + "]"
|
||||||
|
} else if p.FromDate != "" {
|
||||||
|
query += " date: [" + p.FromDate + " *]"
|
||||||
|
} else if p.ToDate != "" {
|
||||||
|
query += " date: [* " + p.ToDate + "]"
|
||||||
|
}
|
||||||
|
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,6 +249,8 @@ func (p *TorrentParam) Clone() TorrentParam {
|
||||||
UserID: p.UserID,
|
UserID: p.UserID,
|
||||||
TorrentID: p.TorrentID,
|
TorrentID: p.TorrentID,
|
||||||
FromID: p.FromID,
|
FromID: p.FromID,
|
||||||
|
FromDate: p.FromDate,
|
||||||
|
ToDate: p.ToDate,
|
||||||
NotNull: p.NotNull,
|
NotNull: p.NotNull,
|
||||||
Null: p.Null,
|
Null: p.Null,
|
||||||
NameLike: p.NameLike,
|
NameLike: p.NameLike,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
|
@ -86,6 +87,8 @@ func searchByQuery(r *http.Request, pagenum int, countAll bool, withUser bool, d
|
||||||
searchParam := common.SearchParam{
|
searchParam := common.SearchParam{
|
||||||
TorrentID: uint(torrentParam.TorrentID),
|
TorrentID: uint(torrentParam.TorrentID),
|
||||||
FromID: uint(torrentParam.FromID),
|
FromID: uint(torrentParam.FromID),
|
||||||
|
FromDate: torrentParam.FromDate,
|
||||||
|
ToDate: torrentParam.ToDate,
|
||||||
Order: torrentParam.Order,
|
Order: torrentParam.Order,
|
||||||
Status: torrentParam.Status,
|
Status: torrentParam.Status,
|
||||||
Sort: torrentParam.Sort,
|
Sort: torrentParam.Sort,
|
||||||
|
@ -122,6 +125,14 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
|
||||||
fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID"))
|
fromID, _ := strconv.Atoi(r.URL.Query().Get("fromID"))
|
||||||
search.FromID = uint(fromID)
|
search.FromID = uint(fromID)
|
||||||
|
|
||||||
|
maxage, err := strconv.Atoi(r.URL.Query().Get("maxage"))
|
||||||
|
if err != nil {
|
||||||
|
search.FromDate = r.URL.Query().Get("fromDate")
|
||||||
|
search.ToDate = r.URL.Query().Get("toDate")
|
||||||
|
} else {
|
||||||
|
search.FromDate = time.Now().AddDate(0, 0, -maxage).Format("2006-01-02")
|
||||||
|
}
|
||||||
|
|
||||||
switch s := r.URL.Query().Get("s"); s {
|
switch s := r.URL.Query().Get("s"); s {
|
||||||
case "1":
|
case "1":
|
||||||
search.Status = common.FilterRemakes
|
search.Status = common.FilterRemakes
|
||||||
|
@ -224,6 +235,14 @@ func searchByQueryPostgres(r *http.Request, pagenum int, countAll bool, withUser
|
||||||
conditions = append(conditions, "torrent_id > ?")
|
conditions = append(conditions, "torrent_id > ?")
|
||||||
parameters.Params = append(parameters.Params, search.FromID)
|
parameters.Params = append(parameters.Params, search.FromID)
|
||||||
}
|
}
|
||||||
|
if search.FromDate != "" {
|
||||||
|
conditions = append(conditions, "date >= ?")
|
||||||
|
parameters.Params = append(parameters.Params, search.FromDate)
|
||||||
|
}
|
||||||
|
if search.ToDate != "" {
|
||||||
|
conditions = append(conditions, "date <= ?")
|
||||||
|
parameters.Params = append(parameters.Params, search.ToDate)
|
||||||
|
}
|
||||||
if search.Category.Sub != 0 {
|
if search.Category.Sub != 0 {
|
||||||
conditions = append(conditions, "sub_category = ?")
|
conditions = append(conditions, "sub_category = ?")
|
||||||
parameters.Params = append(parameters.Params, search.Category.Sub)
|
parameters.Params = append(parameters.Params, search.Category.Sub)
|
||||||
|
|
Référencer dans un nouveau ticket