func NewSearcher(logger log.Logger, terms []*SearchTerm, minResults int, maxAge time.Duration, client *anaconda.TwitterApi, db DB) (*Searcher, error) {
	if terms == nil || len(terms) < 1 {
		return nil, errors.New("searcher: terms must not be nil or empty")
	}
	for _, t := range terms {
		if t.Topic == "" {
			return nil, errors.New("searcher: search topics must not be empty")
		}
		if t.Query == "" {
			return nil, errors.New("searcher: search queries must not be empty")
		}
	}
	if minResults < 1 {
		return nil, errors.New("searcher: minResults must be > 0")
	}
	sr := &Searcher{
		twitterClient: client,
		httpClient:    &http.Client{},
		db:            db,
		maxAge:        maxAge,
		minResults:    minResults,
		logger:        logger,
		searchTerms:   terms,
	}
	sr.twitterClient.HttpClient = sr.httpClient
	_, err := sr.twitterClient.VerifyCredentials()
	if err != nil {
		return nil, errors.Wrap(err, "could not authenticate to Twitter API")
	}
	return sr, nil
}
NewSearcher creates a new Searcher with the given search terms. It will attempt to fetch minResults per search term and return tweets newer than maxAge.
package centiment
import (
	"context"
	"math"
	"net/http"
	"net/url"
	"strconv"
	"strings"
	"sync"
	"time"
	"github.com/ChimeraCoder/anaconda"
	"github.com/go-kit/kit/log"
	"github.com/gosimple/slug"
	"github.com/pkg/errors"
	"golang.org/x/text/unicode/norm"
	languagepb "google.golang.org/genproto/googleapis/cloud/language/v1"
)
type SearchTerm struct {
	Topic string
	Query string
}
func (st *SearchTerm) buildQuery() string {
	st.Query = strings.TrimSpace(st.Query)
	return st.Query
}
type SearchResult struct {
	searchTerm *SearchTerm
	tweetID    int64
	retweet    bool
	content    string
}
func (s *SearchResult) sentimentRequest() *languagepb.AnalyzeSentimentRequest {
	return &languagepb.AnalyzeSentimentRequest{
		Document: &languagepb.Document{
			Source: &languagepb.Document_Content{
				Content: string(norm.NFC.Bytes([]byte(s.content))),
			},
			Type:     languagepb.Document_PLAIN_TEXT,
			Language: "en",
		},
	}
}
type Searcher struct {
	twitterClient *anaconda.TwitterApi
	db            DB
	httpClient    *http.Client
	logger        log.Logger
	wg            sync.WaitGroup
	searchTerms   []*SearchTerm
	minResults    int
	maxAge        time.Duration
}