Documentation
¶
Overview ¶
Package filter provides pattern matching and filtering functionality for RSS items.
Index ¶
Constants ¶
const MaxPatternLength = 512
MaxPatternLength is the maximum allowed length for a pattern.
Variables ¶
var ( ErrInvalidPattern = errors.New("invalid pattern") ErrInvalidRegex = errors.New("invalid regular expression") ErrEmptyPattern = errors.New("pattern cannot be empty") ErrPatternTooLong = errors.New("pattern exceeds maximum length") ErrUnknownType = errors.New("unknown pattern type") )
Pattern matching errors.
Functions ¶
func ValidateRegexPattern ¶
ValidateRegexPattern validates a regex pattern without creating a matcher.
Types ¶
type FilterService ¶
type FilterService interface {
// MatchRules checks if a torrent title matches any enabled filter rule.
// Returns the matched rule and true if a match is found, nil and false otherwise.
MatchRules(title string, siteID, rssID *uint) (*models.FilterRule, bool)
// MatchRulesWithInput checks if input matches any enabled filter rule.
// Supports matching against title, tag, or both based on rule configuration.
MatchRulesWithInput(input MatchInput, siteID, rssID *uint) (*models.FilterRule, bool)
// MatchRulesForRSS checks if a torrent title matches any filter rule associated with the RSS.
// This uses the many-to-many association table for rule lookup.
// Returns the matched rule and true if a match is found, nil and false otherwise.
MatchRulesForRSS(title string, rssID uint) (*models.FilterRule, bool)
// MatchRulesForRSSWithInput checks if input matches any filter rule associated with the RSS.
// Supports matching against title, tag, or both based on rule configuration.
MatchRulesForRSSWithInput(input MatchInput, rssID uint) (*models.FilterRule, bool)
// ShouldDownload determines if a torrent should be downloaded based on filter rules.
// Returns true if the torrent should be downloaded, along with the matched rule (if any).
ShouldDownload(title string, isFree bool, siteID, rssID *uint) (bool, *models.FilterRule)
// ShouldDownloadWithInput determines if a torrent should be downloaded based on filter rules.
// Supports matching against title, tag, or both based on rule configuration.
ShouldDownloadWithInput(input MatchInput, isFree bool, siteID, rssID *uint) (bool, *models.FilterRule)
// ShouldDownloadForRSS determines if a torrent should be downloaded based on RSS-associated filter rules.
// This uses the many-to-many association table for rule lookup.
// Returns true if the torrent should be downloaded, along with the matched rule (if any).
ShouldDownloadForRSS(title string, isFree bool, rssID uint) (bool, *models.FilterRule)
// ShouldDownloadForRSSWithInput determines if a torrent should be downloaded based on RSS-associated filter rules.
// Supports matching against title, tag, or both based on rule configuration.
ShouldDownloadForRSSWithInput(input MatchInput, isFree bool, rssID uint) (bool, *models.FilterRule)
// GetEnabledRules returns all enabled filter rules ordered by priority.
GetEnabledRules() ([]models.FilterRule, error)
// GetRulesForRSS returns all enabled filter rules associated with an RSS subscription.
// Uses the many-to-many association table.
GetRulesForRSS(rssID uint) ([]models.FilterRule, error)
// RefreshCache refreshes the cached matchers from the database.
RefreshCache() error
}
FilterService provides filter rule matching functionality.
func NewFilterService ¶
func NewFilterService(db *gorm.DB) FilterService
NewFilterService creates a new FilterService.
type KeywordMatcher ¶
type KeywordMatcher struct {
// contains filtered or unexported fields
}
KeywordMatcher implements case-insensitive keyword matching.
func NewKeywordMatcher ¶
func NewKeywordMatcher(pattern string) (*KeywordMatcher, error)
NewKeywordMatcher creates a new KeywordMatcher.
func (*KeywordMatcher) Match ¶
func (m *KeywordMatcher) Match(title string) bool
Match returns true if the title contains the keyword (case-insensitive).
func (*KeywordMatcher) Pattern ¶
func (m *KeywordMatcher) Pattern() string
Pattern returns the original pattern string.
func (*KeywordMatcher) Type ¶
func (m *KeywordMatcher) Type() PatternType
Type returns the pattern type.
func (*KeywordMatcher) Validate ¶
func (m *KeywordMatcher) Validate() error
Validate checks if the pattern is valid.
type MatchInput ¶
MatchInput represents the input fields for matching against filter rules.
type MatchResult ¶
type MatchResult struct {
Matched bool
Rule *models.FilterRule
ShouldDownload bool
}
MatchResult represents the result of a filter match.
type PatternMatcher ¶
type PatternMatcher interface {
// Match returns true if the title matches the pattern.
Match(title string) bool
// Validate checks if the pattern is valid.
Validate() error
// Pattern returns the original pattern string.
Pattern() string
// Type returns the pattern type.
Type() PatternType
}
PatternMatcher defines the interface for pattern matching.
func NewMatcher ¶
func NewMatcher(patternType PatternType, pattern string) (PatternMatcher, error)
NewMatcher creates a new PatternMatcher based on the pattern type.
type PatternType ¶
type PatternType string
PatternType represents the type of pattern matching to use.
const ( // PatternKeyword matches if the title contains the keyword (case-insensitive). PatternKeyword PatternType = "keyword" // PatternWildcard uses * and ? wildcards for matching. PatternWildcard PatternType = "wildcard" // PatternRegex uses regular expressions for matching. PatternRegex PatternType = "regex" )
type RegexMatcher ¶
type RegexMatcher struct {
// contains filtered or unexported fields
}
RegexMatcher implements regular expression pattern matching.
func NewRegexMatcher ¶
func NewRegexMatcher(pattern string) (*RegexMatcher, error)
NewRegexMatcher creates a new RegexMatcher.
func (*RegexMatcher) Match ¶
func (m *RegexMatcher) Match(title string) bool
Match returns true if the title matches the regex pattern.
func (*RegexMatcher) Pattern ¶
func (m *RegexMatcher) Pattern() string
Pattern returns the original pattern string.
func (*RegexMatcher) Type ¶
func (m *RegexMatcher) Type() PatternType
Type returns the pattern type.
func (*RegexMatcher) Validate ¶
func (m *RegexMatcher) Validate() error
Validate checks if the pattern is valid.
type WildcardMatcher ¶
type WildcardMatcher struct {
// contains filtered or unexported fields
}
WildcardMatcher implements wildcard pattern matching using * and ? characters. * matches any sequence of characters (including empty). ? matches exactly one character.
func NewWildcardMatcher ¶
func NewWildcardMatcher(pattern string) (*WildcardMatcher, error)
NewWildcardMatcher creates a new WildcardMatcher. It converts the wildcard pattern to a regular expression.
func (*WildcardMatcher) Match ¶
func (m *WildcardMatcher) Match(title string) bool
Match returns true if the title matches the wildcard pattern.
func (*WildcardMatcher) Pattern ¶
func (m *WildcardMatcher) Pattern() string
Pattern returns the original pattern string.
func (*WildcardMatcher) Type ¶
func (m *WildcardMatcher) Type() PatternType
Type returns the pattern type.
func (*WildcardMatcher) Validate ¶
func (m *WildcardMatcher) Validate() error
Validate checks if the pattern is valid.