lib/chatterbot/search.rb in chatterbot-0.9.2 vs lib/chatterbot/search.rb in chatterbot-0.9.3
- old
+ new
@@ -2,10 +2,12 @@
#
# handle Twitter searches
module Search
+ MAX_SEARCH_TWEETS = 1000
+
@skip_retweets = true
#
# modify a query string to exclude retweets from searches
#
@@ -23,24 +25,23 @@
# internal search code
def search(queries, opts = {}, &block)
debug "check for tweets since #{since_id}"
+ max_tweets = opts.delete(:limit) || MAX_SEARCH_TWEETS
+
if queries.is_a?(String)
queries = [queries]
end
-
#
# search twitter
#
queries.each { |query|
debug "search: #{query} #{default_opts.merge(opts)}"
- result = client.search( query, default_opts.merge(opts) )
- update_since_id(result)
-
@current_tweet = nil
- result.each { |s|
+ client.search( query, default_opts.merge(opts) ).take(max_tweets).each { |s|
+ update_since_id(s)
debug s.text
if has_whitelist? && !on_whitelist?(s)
debug "skipping because user not on whitelist"
elsif block_given? && !on_blacklist?(s) && !skip_me?(s) && !skippable_retweet?(s)
@current_tweet = s