Skip to main content
TRAC: Full Boolean Operator Guide

This article provides an in-depth look at the various operators utilised when crafting Boolean expressions.

Ashvin Jalabhay avatar
Written by Ashvin Jalabhay
Updated this week

Learning Outcomes:

  • Understand the purpose and usage of different Boolean operators.

  • Learn how to construct Boolean expressions effectively.

  • Recognise the limitations of Boolean expressions and character limits.

  • Gain knowledge about best practices when using Boolean.


Welcome to the comprehensive guide to Boolean operators! In this guide, you'll explore the different operators employed when creating Boolean expressions, along with detailed explanations of their functions.

The snapshot below demonstrates each operator in action, providing you with a clear understanding of how they should be utilised when constructing a Boolean expression.

OPERATOR                      EXAMPLE

"Exact Phrase" "apple iphone"
AND cat AND toy
OR cat OR mouse OR fish
NOT cat AND NOT mouse
(parentheses) (cat OR dog) AND (toy OR food)
"Proximity Operator"~n "cat toys"~4
LOCATION LOCATION(US OR IT|Tuscany)
LANG LANG(en OR fr)
MEDIA MEDIA(video OR photo)
NOT SITE NOT SITE(amazon.com OR guardian.com)
IN_URL IN_URL((cat OR dog) AND (food OR toy))
BY_TWITTER BY_TWITTER(@handle1 OR @handle2 OR @handle3)
NOT BY_TWITTER NOT BY_TWITTER(@handle1 OR @handle2)
NOT RT (cat OR mouse) AND NOT RT
NOT RT_OF (cat) AND NOT RT_OF(@h1 OR @h2)
NOT QUOTE (cat OR mouse) AND NOT QUOTE
NOT REPLY (dog OR bird) AND NOT REPLY
SAMPLE (apple AND mac) AND SAMPLE 25
PINTEREST PINTEREST (apple OR juice)
TWITCH TWITCH (apple AND "apple iPhone")
THREADS THREADS (apple AND "apple iPhone")

PREMIUM OPERATORS EXAMPLE
Wildcard* space* AND (elon OR nasa)
!"Case SensiTiviTy" !"LASER beam"
NEAR/X (cat OR dog) NEAR/5 (food OR drink)


Query Operators

The Exact Phrase Operator

"apple iphone"
  • This will collect mentions of the exact phrase 'apple iphone' in any post.

  • You must wrap your terms in "double quotes", not 'single quotes'.

  • This operator is case insensitive, which means using exact phrase will match both uppercase and lowercase terms, for example "Apple iPhone" or "APPLE iPhone".


The AND Operator

apple AND juice
  • This will collect posts that contain the terms 'apple' and 'juice' when they appear together.

  • Operator AND must be capitalised.

  • Both terms must appear in the post or article.

  • However, the terms can appear in any order, or side by side. For example, "I am drinking apple juice.", or "You can juice this apple."

  • Using the AND operator is useful when you want to be more specific and collect relevant results and filter out any unwanted noise.


The OR Operator

apple OR iphone OR mobile
(https://www.guardian.co.uk OR https://www.thesun.co.uk )
  • In the first example, this will collect posts that contain any of the terms 'apple' or 'iphone' or 'mobile'.

  • Operator OR must be capitalised.

  • For a match, only one of the specified terms has to be present.

  • As such use of this operator will bring in more mentions, which sometimes can be irrelevant.

  • Note, if using Boolean mode to create a Content search, the list of urls can only be expressed in OR. And, because there is no way to know if the parenthesis is part of the url, you also need leave a space between the url and the closing bracket, as shown in the above example.


The NOT Operator

(apple) AND NOT (iphone)
  • This will collect posts that contain the term 'apple' as long as the term 'iphone' is not mentioned in that same post or article.

  • Operator NOT must be capitalised.

  • This operator cannot be used alone, i.e. without any inclusion terms.

  • For example just writing this: NOT iphone, is not a valid expression.

  • Whereas writing this: (apple) AND NOT (iphone), is a valid expression.

  • An important caveat to using the NOT operator is that there is limit imposed on the terms you can blacklist in an expression. This limit is based on the length of your entire query, not necessarily on the number of terms.

  • As such it is near impossible to give an exact number of terms you can blacklist, however as a general rule, you should always try and keep your keywords blacklist small.

  • Use the NOT operator to exclude posts that contain certain terms from being collected into your results, effectively filtering out any noise.


The Parenthesis Operator ( )

apple AND (juice OR pie)
(#bitcoin OR #cryptobear) AND (crypto OR cryptocurrency)
  • The first example will collect posts that contain the terms 'apple' and 'juice' appearing together, OR posts that contain the terms 'apple' and 'pie' appearing together.

  • The second example will collect posts that contain the terms #bitcoin and crypto, or posts that contain the terms #bitcoin and cryptocurrency. This syntax can also match posts that contain the terms #cryptobear and crypto or #cryptobear and cryptocurrency.

  • Note how parenthesis condenses the second expression into fewer repetitions.

  • Parenthesis is useful for grouping AND/OR terms together.

  • Operator AND, and Operator OR must always be capitalised.

The Proximity Operator ~ (tilde)

"apple juice"~5
  • This will collect mentions of the exact phrase 'apple juice', as well as mentions of 'apple' and 'juice', within 5 words of each other.

  • For example, this post: 'This drink was freshly made with apple, orange and mango juice’, will be a match.

  • The maximum number of words you can specify when using the proximity operator is 6.

  • You must always wrap the terms in "double quotes", not single quotes.

  • You can wrap 2 or more keywords in double quotes, e.g. "organic apple juice"~6.

  • NB For X, if your keywords are in the opposite order, they cannot be more than N-2 tokens from each other.

  • For example this query: "apple iphone mobile"~6, will match this phrase: "Mobile devices such as the apple iphone are popular among teens." Since the order is switched here, there can only be N-2, i.e. 4 (words) apart.

  • However, this post: "Mobile devices such as the iphone by apple, are the best." will not be a match. This is because the order is switched, and there are now 5 words between each keyword.

  • This rule applies to X data only, other data sources are not affected by reverse order.

  • NB For X, if you use this operator, you may not retrieve historic data. You will be only allowed to collect real-time data only


Target Operators

The LOCATION Operator

trump AND LOCATION (GB OR IT|Tuscany)
(trump OR obama) AND LOCATION ("GB" OR "US" OR "ES")
  • The first example will collect posts containing the keyword 'trump', that are from United States or Italy. However, any posts from Italy should only be from the Tuscany Region, not the whole of Italy.

  • So the use of the pipe or vertical bracket after a country is always followed by a list of regions for that specific country. For example, LOCATION (GB|England OR Wales OR Scotland).

    • Adding regions will prevent historic data from being collected from X/Twitter

  • Operator LOCATION must always be capitalised.

  • When specifying a list of locations, these can only be in 'OR' logic. So writing this: LOCATION (GB OR US) is a valid expression.

  • But writing this: LOCATION (GB AND US) is not a valid expression.

  • NB The LOCATION operator cannot be negated or otherwise enclosed in a NOT expression

  • And lastly the LOCATION operator must always be "in AND with the rest of the expression".

  • For example: apple AND LOCATION (IT OR FR) is a valid expression.

  • However writing this: (trump AND LOCATION US) OR (juice AND LOCATION IT) is not valid.

    A full list of our locations can be found here:

The LANG Operator

apple AND LANG (en OR fr)
  • This will collect posts containing the keyword 'apple', that are written in English or French.

  • Operator LANG must always be capitalised.

  • The languages must be closed in parentheses with the LANG operator.

  • When specifying a list of languages, these can only be listed in 'OR' logic.

  • NB The LANG operator cannot be negated or otherwise enclosed in a NOT expression

  • Lastly, the LANG operator must be "in AND with the rest of the expression".

  • For example: (gateau OR potatoes) AND LANG (en OR fr) is a valid expression.

  • However writing this: (gateau AND LANG fr) OR (smashed AND potatoes AND LANG en) are not valid expressions.

    A full list of our languages can be found here:

The MEDIA Operator

MEDIA (video OR photo)
  • This will collect posts that contain either videos or photos.

  • Operator MEDIA must always be capitalised.

  • The media type you choose must be in the list of our supported media types, which are photo, video, link

  • When specifying a list of media types, these can only listed in 'OR' logic.

  • NB The operator cannot be negated or otherwise enclosed in a NOT expression.

  • Lastly, the MEDIA operator must be "in AND with the rest of the expression".

  • For example writing this: (apple OR juice) AND MEDIA (video OR photo) is a valid expression.

  • However writing this: (apple AND MEDIA video) is not a valid expression.

The NOT SITE Operator

NOT SITE (amazon.com OR guardian.com)
  • This will exclude posts from the specific domains listed.

  • Operator NOT SITE must always be capitalised.

  • When specifying a list of domains to exclude, these can only be listed in 'OR' logic.

  • For example: (apple) NOT SITE (guardian.com OR techcrunch.com OR thesun.com) is a valid expression.

  • However writing this: (apple) NOT SITE (guardian.com AND techcrunch.com AND thesun.com) is not a valid expression.

  • An important caveat to using the NOT SITE operator is that there is a limit imposed on the sites you can blacklist in an expression. This limit is based on the length of the entire query, not necessarily the number of sites you want to block.

  • As such it is near impossible to give an exact number of sites you can block, however as a general rule, you should always try and keep your sites blacklist small.


X Only Operators

The BY_TWITTER Operator

apple AND BY_TWITTER (@ariesbelle OR @abc3d)
  • This will collect tweets that contain the keyword 'apple' and have been written by the X user @ariesbelle, or by the X user called @abc3d.

  • Operator BY_TWITTER must always be capitalised, and accepts both usernames or user ids.

  • When specifying a list of authors, these can only be listed in 'OR' logic.

  • Therefore writing this: BY_TWITTER (@ariesbelle OR @abc3d) is a valid expression.

  • However writing this: BY_TWITTER (@pulsarplatform AND @twitter) is not a valid expression.

The NOT BY_TWITTER Operator

(apple) AND NOT BY_TWITTER @ariesbelle
  • This will collect tweets that contain the keyword 'apple' but will exclude any tweets that have been written by the X user @ariesbelle.

  • Use this operator to block tweets from spam accounts.

  • Operator NOT BY_TWITTER must always be capitalised and accepts both usernames or user ids.

  • When specifying a list of authors, these can only be listed in 'OR' logic.

  • For example, writing this: NOT BY_TWITTER (@ariesbelle OR @abc3d OR @pulsarplatform) is a valid expression.

  • But writing this: NOT BY_TWITTER (@pulsarplatform AND @twitter) is not a valid expression.

  • Another caveat to using the NOT_BY_TWITTER operator is that there is limit imposed on the authors you can blacklist in an expression. This limit is based on the length of your entire query, not necessarily the number of authors you want to block. As such it is near impossible to give an exact estimate on the number of authors you can blacklist, however as a general rule, you should always try and keep your blacklist small.

The NOT RT Operator

(apple AND juice) AND NOT RT
  • This will collect 'original' tweets only, that contain the keywords 'apple' and 'juice', appearing together in the same tweet, and will exclude any 'retweets' of those posts.

  • Operator NOT RT must always be capitalised.

  • The operator must be "in AND with the rest of the expression".

  • For example: (apple OR juice OR fruit) AND NOT RT is a valid expression.

  • However writing this: (apple OR Juice OR fruit AND NOT RT) is not a valid expression.

  • Use this operator if you want to restrict your data collection to just original tweets and exclude all retweets.

The NOT RT_OF Operator

(apple OR juice) AND NOT RT_OF @riesbelle 
  • This will collect tweets that contain the keyword 'apple' or 'juice', but will exclude any retweets of a specific X user, in this case > @ariesbelle.

  • So if you are searching for mentions of 'apple' and user @ariesbelle tweets something about apples, any re-tweets of @ariesbelle's tweet will be excluded from your results.

  • Operator NOT_RT_OF must always be capitalised.

  • If you have a list of authors whose retweets you want to exclude, these can be specified in 'OR'.

  • You can use this operator to block spam accounts.

The NOT QUOTE Operator

(apple AND juice) AND NOT QUOTE
  • This will prevent your search from collecting tweets that quote other tweets.

  • Operator NOT QUOTE must always be capitalised.

  • The operator must be "in AND with the rest of the expression".

  • For example: (apple OR juice OR fruit) AND NOT QUOTE is a valid expression.

  • However writing this: (apple OR Juice OR fruit AND NOT QUOTE) is not a valid expression.

The NOT REPLY Operator

(apple AND juice) AND NOT REPLY
  • This will avoid collecting tweets that are replies to other tweets.

  • Operator NOT REPLY must always be capitalised.

  • The operator must be "in AND with the rest of the expression".

  • For example: (apple OR juice OR fruit) AND NOT REPLY is a valid expression.

  • However writing this: (apple OR Juice OR fruit AND NOT REPLY) is not a valid expression.

The IN_URL Operator

IN_URL (trump OR melania) AND NOT donald
  • This will collect tweets with a link whose url contains the keywords specified

  • In the given example, this will collect any tweets with a link whose url contains the keywords 'trump' or 'melania', but not the keyword 'donald'.

  • Operator IN_URL must always be capitalised.

  • Keywords must not contain the @ symbol

  • When you specify the URL keywords, these can be in 'AND', or in 'OR' logic.

  • For example writing this: IN_URL (trump AND president) is valid; or writing this: IN_URL (trump OR president) is also still valid.

  • However, writing this: IN_URL ("trump melania"~3) is not a valid expression.

The SAMPLE operator

(apple OR oranges ) AND SAMPLE 10
  • This operator will sample your real-time tweets down to the specified percentage.

  • In the given example, this will collect 10% of the tweets that are available on X that contain either the keyword apples or the keyword oranges.

  • Operator SAMPLE must always be capitalised.

  • The operator must be "in AND with the rest of the expression".


Source Operators

The PINTEREST Operator

(apple OR juice) OR PINTEREST (apple OR juice)

  • The PINTEREST Operator is designed for use when PINTEREST is selected as a data source.

  • The Operator will be followed, in parentheses by whatever words one wishes to search for on Pinterest.

  • This operator should be in OR with the rest of the main expression (the keyword part), whilst the operators NOT, LANGUAGE, LOCATION, and MEDIA remain in AND.

  • Both OR and AND operators work here, but the key thing is that it needs to be OR before the operator. For example: OR PINTEREST (A AND B OR C AND D OR E).

  • The AND NOT Operator is not supported here.

  • The keyword limit for Pinterest is 20.


The THREADS Operator

(apple OR juice) OR THREADS (apple OR juice)

  • The THREADS Operator is designed for use when Threads is selected as a data source.

  • The Operator will be followed, in parentheses by whatever words one wishes to search for on Threads.

  • This operator should be in OR with the rest of the main expression (the keyword part), whilst the operators NOT, LANGUAGE, LOCATION, and MEDIA remain in AND.

  • Both OR and AND operators work here, but the key thing is that it needs to be OR before the operator. For example: OR THREADS (A AND B OR C AND D OR E).

  • The AND NOT Operator is not supported here.

  • The keyword limit for Threads is 20.


Premium Operators

19. The Wildcard * Operator

space* AND (elon OR nasa)

  • The wildcard operator lets you search for terms that start with a partial term but may end in anything else, including nothing!

  • For example, the above would pick up spacecraft, spaceship, space

  • It must be used at the end of a term

  • it must be used in conjunction with other terms (the AND bit is necessary)

  • It is for realtime only


20. The !"Case Sensitivity" Operator

!"LASER beam"

  • The Case sensitivity operator is designed to match exact case of the term in the parentheses

  • It is used at the beginning of a quoted term

  • it cannot be used in conjunction with any other special operators (AND and OR only)

  • It is for realtime only


21. The NEAR/X Operator

(cat OR dog) NEAR/5 (food OR drink)

  • The NEAR operator acts like the proximity (~) operator but allows you to check multiple terms against multiple other terms

  • The NEAR operator has the same limit as the proximity operator

  • The NEAR operator cannot contain any other premium operators

  • The NEAR operator is for realtime only



One Final Word on Boolean!

Employing Boolean operators can make your search configuration simpler and more efficient. However, akin to a wizard, there are certain limitations and considerations to bear in mind:

  • We must adhere to a 5000 character limit imposed by our partners when submitting queries to them, meaning your Boolean expression must operate within these confines.

  • For instance, in the case of blacklisting, we advise using the NOT operator, ensuring your blacklisted terms, authors, or sites, along with your other operators, are in conjunction with your keyword group using the AND operator.

  • While we endorse the grouping of keywords, it's crucial not to create overly large keyword groups. This is because your query becomes increasingly complex, particularly when combined with blacklisted keywords, authors, and sites, making it unfeasible for us to execute.

📝 Note: All mentions of a keyword or phrase will be collected from X unless a hashtag or handle are explicitly stated. For example, 'orangejuice' will be collected from X, (including posts containing 'orangejuice', '@orangejuice', or #orangejuice).


We hope you enjoyed reading this article! 📚

If you have any questions or would like to learn more, please don't hesitate to reach out to our support team via live chat. 🚀

Did this answer your question?