Skip to content

Commit

Permalink
fixed cheatsh unknown topic bug
Browse files Browse the repository at this point in the history
  • Loading branch information
spy16 committed Sep 23, 2018
1 parent e2d97b4 commit 788223a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
15 changes: 14 additions & 1 deletion sources/cheatsh/cheatsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cheatsh

import (
"context"
"strings"

"github.com/shivylp/radium"
)
Expand All @@ -22,5 +23,17 @@ type CheatSh struct {
func (csh CheatSh) Search(ctx context.Context, query radium.Query) ([]radium.Article, error) {
transformLanguageQuery(&query)

return executeRequest(ctx, query)
raw, err := executeRequest(ctx, query)
if err != nil {
return nil, err
}

results := []radium.Article{}
for _, res := range raw {
if !strings.HasPrefix(res.Content, "Unknown topic") {
results = append(results, res)
}
}

return results, nil
}
12 changes: 11 additions & 1 deletion strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (sr *safeResults) extend(results []Article, srcName string, logger Logger)
logger.Warnf("ignoring invalid result from source '%s': %s", srcName, err)
continue
}
res.Source = srcName

sr.results = append(sr.results, res)
}
Expand Down Expand Up @@ -104,7 +105,16 @@ func (nth *NthResult) Execute(ctx context.Context, query Query, srcs []Registere
return nil, err
}

results = append(results, srcResults...)
for _, res := range srcResults {
if err := res.Validate(); err != nil {
nth.Warnf("ignoring invalid result from '%s': %s", src.Name, err)
continue
}

res.Source = src.Name
results = append(results, res)
}

if len(results) >= nth.stopAt {
break
}
Expand Down

0 comments on commit 788223a

Please sign in to comment.