mirror of
https://github.com/idanoo/autobrr
synced 2025-07-23 00:39:13 +00:00
feat(releases): implement keyword search (#564)
* feat(releases): implement reserved keyword search * implement filter / hdr * implement quote support * implement wildcard for decimals * feat(release): specify table name in map
This commit is contained in:
parent
38795be9ea
commit
5260777b6b
1 changed files with 32 additions and 1 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"regexp"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/autobrr/autobrr/internal/domain"
|
"github.com/autobrr/autobrr/internal/domain"
|
||||||
|
@ -144,7 +145,37 @@ func (repo *ReleaseRepo) findReleases(ctx context.Context, tx *Tx, params domain
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Search != "" {
|
if params.Search != "" {
|
||||||
queryBuilder = queryBuilder.Where("r.torrent_name LIKE ?", fmt.Sprint("%", params.Search, "%"))
|
reserved := map[string]string{
|
||||||
|
"title": "r.title",
|
||||||
|
"group": "r.release_group",
|
||||||
|
"category": "r.category",
|
||||||
|
"season": "r.season",
|
||||||
|
"episode": "r.episode",
|
||||||
|
"year": "r.year",
|
||||||
|
"resolution": "r.resolution",
|
||||||
|
"source": "r.source",
|
||||||
|
"codec": "r.codec",
|
||||||
|
"hdr": "r.hdr",
|
||||||
|
"filter": "r.filter",
|
||||||
|
}
|
||||||
|
|
||||||
|
search := strings.TrimSpace(params.Search)
|
||||||
|
for k, v := range reserved {
|
||||||
|
r := regexp.MustCompile(fmt.Sprintf(`(?:%s:)(?P<value>'.*?'|".*?"|\S+)`, k))
|
||||||
|
if reskey := r.FindAllStringSubmatch(search, -1); len(reskey) != 0 {
|
||||||
|
filter := sq.Or{}
|
||||||
|
for _, found := range reskey {
|
||||||
|
filter = append(filter, sq.Like{v: strings.ReplaceAll(strings.Trim(strings.Trim(found[1], `"`), `'`), ".", "_") + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
queryBuilder = queryBuilder.Where(filter)
|
||||||
|
search = strings.TrimSpace(r.ReplaceAllLiteralString(search, ""))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(search) != 0 {
|
||||||
|
queryBuilder = queryBuilder.Where(sq.Like{"r.torrent_name": search + "%"})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Filters.Indexers != nil {
|
if params.Filters.Indexers != nil {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue