Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Cette révision appartient à :
kilo 2017-11-20 01:26:35 +00:00 révisé par GitHub
révision d32345c184
4 fichiers modifiés avec 50 ajouts et 12 suppressions

Voir le fichier

@ -23,6 +23,7 @@ type Navigation struct {
// SearchForm struct used to display the search form
type SearchForm struct {
search.TorrentParam
Search string
Category string
ShowItemsPerPage bool
ShowRefine bool
@ -50,6 +51,7 @@ func NewNavigation() Navigation {
func NewSearchForm(c *gin.Context) SearchForm {
sizeType := c.DefaultQuery("sizeType", "m")
return SearchForm{
Search: c.Query("q"),
Category: "_",
ShowItemsPerPage: true,
ShowRefine: false,

Voir le fichier

@ -8,7 +8,7 @@
</select>
{{end}}
{{block search_button() }}
<input class="form-input search-box" name="q" placeholder="{{ if Search.UserName == ""}}{{ T("search")}}{{else}}{{ T("search_from_specific_user", Search.UserName)}}{{end}}" type="text" value="{{Search.NameLike}}"/>
<input class="form-input search-box" name="q" placeholder="{{ if Search.UserName == ""}}{{ T("search")}}{{else}}{{ T("search_from_specific_user", Search.UserName)}}{{end}}" type="text" value="{{Search.Search}}"/>
<button type="submit" class="form-input icon-search"></button><button type="submit" class="form-input refine" name="refine" value="1">{{ T("refine")}}</button>
{{end}}
{{block search_refine(url="") }}
@ -19,7 +19,7 @@
<div class="refine-container-1">
<span class="form-refine">
<span class="spacing">{{ T("search_for") }}:</span>
<input type="text" class="form-input refine-searchbox" size="30" name="q" value="{{Search.NameLike}}" placeholder="{{ T("search_for") }}"/><select name="c" class="form-input refine-category">
<input type="text" class="form-input refine-searchbox" size="30" name="q" value="{{Search.Search}}" placeholder="{{ T("search_for") }}"/><select name="c" class="form-input refine-category">
<option value="_">{{ T("all_categories")}}</option>
{{ range _, cat := GetCategories(true, true) }}
<option value="{{ cat.ID }}" {{if Search.Category == cat.ID }}selected{{end}}>{{ T(cat.Name) }}</option>
@ -52,9 +52,10 @@
</span>
<span class="form-refine">
<span class="spacing">{{ T("from")}}</span>
<input class="form-input refine-date" name="fromDate" type="date" value="{{Search.FromDate}}" placeholder="YYYY/MM/DD"/>
<input class="form-input refine-date" name="fromDate" type="text" value="{{Search.FromDate}}" placeholder="YYYY/MM/DD"/>
{{ T("to")}}
<input class="form-input refine-date spacing" size="7" name="toDate" type="date" value="{{Search.ToDate}}" placeholder="YYYY/MM/DD"/>
<input class="form-input refine-date spacing" size="7" name="toDate" type="text" value="{{Search.ToDate}}" placeholder="YYYY/MM/DD"/>
{{ T("exclude_user") }}: <input type="text" name="nuserID" placeholder="UserID" value="" class="form-input refine-userid" style="width: 62px;">
</span>
<span class="form-refine" style="margin-bottom: 2px;">
<span class="spacing">{{T("sort_by")}}</span>
@ -70,7 +71,6 @@
<option value="true">{{T("ascending")}}</option>
<option value="false" {{if !Search.Order}}selected{{end}}>{{T("descending")}}</option>
</select>
{{ T("exclude_user") }}: <input type="text" name="nuserID" placeholder="UserID" value="" class="form-input refine-userid" style="width: 62px;">
</span>
</div>
<div class="refine-container-2">

Voir le fichier

@ -40,6 +40,7 @@ type TorrentParam struct {
ToDate DateFilter
NotNull string // csv
NameLike string // csv
Exclude []string
Languages publicSettings.Languages
MinSize SizeBytes
MaxSize SizeBytes
@ -67,12 +68,16 @@ func (p *TorrentParam) Identifier() string {
for _, v := range p.TorrentID {
ids += fmt.Sprintf("%d", v)
}
excluded := ""
for _, v := range p.Exclude {
ids += fmt.Sprintf("%s", v)
}
// Tags identifier
tags := strings.Join(p.Tags, ",")
tags += p.VideoQuality
dbids := fmt.Sprintf("%d%d%d%s", p.AnidbID, p.VndbID, p.VgmdbID, p.Dlsite)
identifier := fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%s%d%s%s%s%t%t%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, dbids, p.FromDate, p.ToDate, p.UserID, ids, cats, tags, p.Full, p.Order, p.Hidden, p.Locked, p.Deleted)
identifier := fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%s%d%s%s%s%s%t%t%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, dbids, p.FromDate, p.ToDate, p.UserID, ids, excluded, cats, tags, p.Full, p.Order, p.Hidden, p.Locked, p.Deleted)
return base64.URLEncoding.EncodeToString([]byte(identifier))
}
@ -117,6 +122,31 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
// Search by name
// We take the search arguments from "q" in url
p.NameLike = strings.TrimSpace(c.Query("q"))
p.Exclude = c.QueryArray("exclude")
nameLength := len(p.NameLike)
//Take the total length of NameLike because we might use it multiple times in the below loop
for i, c := range p.NameLike {
//Search if NameLike contains a '-' that isn't in a middle of a word
if c == '-' && (i == 0 || p.NameLike[i - 1] == ' ') && i + 1 < nameLength {
end := nameLength
for idx, character := range p.NameLike[i:] {
//Search for the end of the word by looking for a space or the end of the string
if character == ' ' {
end = i + idx
break
}
}
p.Exclude = append(p.Exclude, p.NameLike[i+1:end])
}
}
for _, word := range p.Exclude {
//Remove the excluded words from the NameLike query
p.NameLike = strings.Replace(p.NameLike, " -" + word, "", -1)
p.NameLike = strings.Replace(p.NameLike, "-" + word, "", -1)
}
// Maximum results returned
// We take the maxximum results to display from "limit" in url
@ -305,6 +335,10 @@ func (p *TorrentParam) toESQuery(c *gin.Context) *Query {
if len(p.Tags) > 0 {
query.Append(p.Tags.ToESQuery())
}
for _, word := range p.Exclude {
query.Append("NOT(torrent_name:"+ word + ")")
}
return query
}
@ -451,15 +485,15 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query {
if len(p.Tags) > 0 {
query.Append(p.Tags.ToDBQuery())
}
//
for _, word := range p.Exclude {
query.Append("torrent_name NOT "+searchOperator, "%"+word+ "%")
}
querySplit := strings.Fields(p.NameLike)
for _, word := range querySplit {
if word[0] == '-' && len(word) > 1 {
//Exclude words starting with -
query.Append("torrent_name NOT "+searchOperator, "%"+word[1:]+"%")
continue
}
firstRune, _ := utf8.DecodeRuneInString(word)
if len(word) == 1 && unicode.IsPunct(firstRune) {
// some queries have a single punctuation character
@ -530,6 +564,7 @@ func (p *TorrentParam) Clone() TorrentParam {
ToDate: p.ToDate,
NotNull: p.NotNull,
NameLike: p.NameLike,
Exclude: p.Exclude,
Languages: p.Languages,
MinSize: p.MinSize,
MaxSize: p.MaxSize,

Voir le fichier

@ -59,6 +59,7 @@ func TestTorrentParam_ToESQuery(t *testing.T) {
}{
{TorrentParam{}, "!status:5"},
{TorrentParam{NameLike: "lol"}, "!status:5"},
{TorrentParam{NameLike: "lol -lol"}, "!status:5"},
{TorrentParam{NameLike: "lol", FromID: 12}, "!status:5 id:>12"},
{TorrentParam{NameLike: "lol", FromID: 12, FromDate: DateFilter("2017-08-01"), ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [2017-08-01 2017-08-05]"},
{TorrentParam{NameLike: "lol", FromID: 12, ToDate: DateFilter("2017-08-05")}, "!status:5 id:>12 date: [* 2017-08-05]"},