Introduction
In previous posts, we have learned how to access Twitter database to collect tweets matching different criteria massively (i.e., Creating a corpus of tweets with Python). In this tutorial we will learn how to make complex searches in Twitter database. We will be taking a look at the different operators that the service supports. Please, note that you can combine several operators in the same search.
Tweet content
- Wildcard:
- Example: San Francisco is *.
- Description: It will return tweets containing “San Francisco is pretty,” “San Francisco is small,” etc.
- Addition:
- Examples: love hate, love AND hate, (love hate)
- Description: Search tweets containing both “love” and “hate”.
- Alternative:
- Example: love OR hate
- Description: Search tweets containing at least one of either “love” or “hate”.
- Exclusion:
- Example: -love
- Description: Search tweets that don’t contain “love”.
- Hashtags:
- Example: #tbt
- Description: Search tweets containing hashtag “tbt”.
- Literal strings:
- Example: “love hate”
- Description: Including quotation marks, Twitter will retrieve tweets containing the sequence “love hate”. Omitting quotation will return an addition search.
- Filter: filter:safe
- Example: love hate filter:safe
- Description: Search tweets containing “love” and “hate” excluding tweets with explicit information.
Users
- Author: from:user
- Example: from:mario_casado_m
- Description: Search tweets posted by @mario_casado_m.
- In reply to…: to:user
- Example: to:mario_casado_m
- Description: Search tweets replying to a @mario_casado_m tweet.
- Mentions: + @user
- Example: +@mario_casado_m
- Description: Search tweets mentioning @mario_casado_m
- Lists: list:user/list
- Example: list:NASA/space-tweets
- Description: Search tweets posted by users that are in NASA space-tweets list.
Tweet info
- Geotag: near:city
- Example: near:Madrid
- Description: Search tweets tagged in Madrid.
- Radius: within:radius
- Example: near:Madrid within:10km
- Description: Search tweets tagged in Madrid within 10 km.
- Time: since:yyyy-mm-dd, until:yyyy-mm-dd
- Example: since:2012-11-02, until:2015-12-01
- Description: Search tweets posted before or after the specified dates.
- Retweet:
- Retweets without quotation: filter:nativeretweets
- Example: love hate filter:nativeretweets
- Description: Search retweets containing “love” and “hate”.
- Quotation retweets: filter:retweets
- Example: love hate filter:nativeretweets
- Description: Search both retweets and quotations containing “love” and “hate”.
- Retweets without quotation: filter:nativeretweets
- Reply: filter:replies
- Example: love hate filter:replies
- Description: Search tweets containing “love” and “hate” that were posted as a reply to other tweets.
- Interactions: min_retweets:N, min_faves:N, min_replies:N
- Example: love hate min_retweets:5
- Description: Search tweets containing “love” and “hate” that have at least 5 retweets.
- Sources: source:tweetdeck, source:twitter_for_iphone, source:twitter_for_android, source:web
- Example: love hate source:tweetdeck
- Description: Search tweets containing “love” and “hate” that were posted using TweetDeck.
Source: Twitter Help Center
Conclusion
In this post, we have come to know Twitter database operators for advanced searching. We can now concoct complex queries to send requests to Twitter API. Remember how to retrieve tweets automaticaly in the post Creating a corpus of tweets with Python.