1

How does Twitter search interpret the order of boolean operators?

Does it support parentheses for clarifying the order of Boolean operators?

If one does a search like

A AND B OR C AND D 

what does Twitter actually search?

1: A AND (B OR (C AND D)) ?

or

2: (A AND B) OR (C AND D) ?

or

3: A AND (B OR C) AND D ?

or

4: ((A AND B) OR C) AND D ?

or something else?


I can now confirm that the answer of @w3d is correct, i.e., if you so a search like

A B OR C D OR E F

it is actually interpreted as

(A AND B) OR (C AND D) OR (E AND F)
3

Does it support parentheses for clarifying the order of Boolean operators?

It does appear to, although I've not found anything in the help docs to support this.

If one does a search like A AND B OR C AND D

OR appears to have a higher precedence than AND (which I'm not even sure is an operator - see below), so this would seem to be equivalent to your #3:

3: A AND (B OR C) AND D

And this returns the same (or very similar) results for me. Placing the parentheses differently returns very different results. I say "similar", because... (and this is an assumption) including parenthesis occasionally returns marginally different results, but I have put this down to the very dynamic nature of Twitter searches. Searching for the same phrase just minutes apart can return different results and then a few minutes later the same results again. (?)

However, as mentioned, I'm not convinced that AND is actually an operator. "and" is the default operator when words are separated by a space. There is no mention of an AND operator on the Twitter Advanced Search Help page. And omitting AND yields the same results. It is quite possible that "AND" is simply stripped from the search phrase as being a "common" word. A AND B OR C AND D is equivalent to A B OR C D

  • Thank you very much for your detailed answer. It is true that writing an SPACE is like putting an <AND>. So this operator exists but as you mentioned it is implicit. What you said about the precedence of <OR> with respect to <AND> is very interesting. I was so surprised that I could not find anything about this on the web. About putting parenthesis I am confused, it seems that putting parentheses sometimes has no effect. – Name Dec 22 '13 at 7:48
  • "precedence of <OR> with respect to <AND> is very interesting." - yes, this is perhaps the opposite to what you might expect (in most programming languages "AND" will take precedence over "OR"). "putting parentheses sometimes has no effect" - this will depend on whether the parentheses changes the natural precedence of the operators. There may also be a "nesting" limit that we are unaware of (does it even support nested parentheses?). – MrWhite Dec 22 '13 at 13:05
2
social media metrics OR analytics

The OR operator will attach to the word that immediately precedes it, very much like order of operations in algebra. For example, the above query will find tweets that mention social media metrics or social media analytics, because the OR links to the metrics and analytics terms. +

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.