Skip to content

Commit

Permalink
fixed filter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jakopako committed Nov 29, 2024
1 parent 41b957e commit 25e07d9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions scraper/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,12 @@ func (c *Scraper) initializeFilters() error {

func (c *Scraper) filterItem(item map[string]interface{}) bool {
nrMatchTrue := 0
foundFields := 0
filterMatchTrue := false
filterMatchFalse := true
for _, f := range c.Filters {
if fieldValue, found := item[f.Field]; found {
foundFields++
if f.Match {
nrMatchTrue++
if f.FilterMatch(fieldValue) {
Expand All @@ -485,6 +487,14 @@ func (c *Scraper) filterItem(item map[string]interface{}) bool {
if nrMatchTrue == 0 {
filterMatchTrue = true
}
// if foundFields < len(c.Filters) that means that we did not get the full item
// with _all_ fields as input to this function and hence we only want
// to return false if we are _sure_ that this item should not be part
// of the final results. And we are only sure if we have a 'match: false'
// match, i.e. filterMatchFalse has been set to false
if foundFields < len(c.Filters) {
return filterMatchFalse
}
return filterMatchTrue && filterMatchFalse
}

Expand Down

0 comments on commit 25e07d9

Please sign in to comment.