# Why do popular search engines not follow the usual AND, OR logic for queries?

I am teaching myself Information Retrieval from Christopher Manning's book (PDF link: http://nlp.stanford.edu/IR-book/pdf/01bool.pdf). I tried Exercise 1.13:

"Try using the Boolean search features on a couple of major web search engines. For instance, choose a word, such as burglar, and submit the queries (i) burglar, (ii) burglar AND burglar, and (iii) burglar OR burglar. Look at the estimated number of results and top hits. Do they make sense in terms of Boolean logic? Often they haven’t for major search engines. Can you make sense of what is going on?"

By my knowledge of Boolean logic, the number of results should be like this:

burglar AND burglar <= burglar OR burglar = burglar

But this isn't so. In fact, on Google, it is:

burglar > burglar OR burglar > burglar AND burglar

So, what exactly is happening behind the scenes? Any pointers?

Note: This is NOT a homework problem, even though it is from the exercise of a textbook.

Nice question!

An exact answer should be given by looking in the search engine source code but here is a possible explanation.

I run the queries at Google

• burglar 33,800,000
• burglar AND burglar 29,200,000
• burglar OR burglar 26,500,000

The results indeed do not respect the expected Boolean relation burglar AND burglar <= burglar OR burglar = burglar

However, that is since the search engine doesn't process the "and" and "or" as binary operator but just as search tokens. Looking for them we get

• And 25,270,000,000
• Or 16,320,000,000

A term alone appears most times. "and" is more common than "or" so a term with "and" is more common than the term with "or"

Note that

• burglar burglar 29,000,000

Apparently looking for documents in which the term appears twice.

By the way, Google's Search operators documentation claim that "OR" should indeed act as a binary operator. You found a case in which they fail to do so.

Note that this behaviour is very specific to search engine. In Bing you get the following results:

• burglar 4,400,000
• burglar AND burglar 1,610,000
• burglar OR burglar 1,610,000

• And 10,400,000,000

• Or 3,750,000,000

• burglar burglar 1,610,000

The number of results is similar for "burglar AND burglar", "burglar OR burglar" and "burglar burglar" though we see that "And" is more popular than "OR". It seems that Bing treatments is the removal of "And" and "OR", possibly as stop words.

Bing documentation suggest the operators "&&" for "and" and "||" for "or". - burglar || burglar 4,400,000 = burglar - burglar && burglar 1,610,000 = burglar burglar

These results fit the claim that when a term appears twice in the search query it should appear at least twice in the document too.

• I suspect this has more to do with quick result-set size estimation code, which probably branches depending on query complexity. I doubt that the number of results returned can be used accurately like an SQL count statement. Commented Jan 11, 2017 at 8:19
• I agree that these are estimations and not exact count. However, even when using a result set per token, there is a logic of token application. I believe that the exact logic is more complex and take care of many sub cases.
– DaL
Commented Jan 11, 2017 at 8:41

Google used to do, to some extend. For a long time, using +word could be used to require the presence of a word. So "a AND b" would be "+a +b" whereas "a OR b" would be "a b" (with a preference to both occurring).

But people did not use it much, so they eventually removed it.

Google thinks it is more important to be able to process natural language queries rather than some mathematical formalism less than 0.1% of the users understand.

Although there are also some other hypotheses why it was removed: Why was the Plus Sign (+) removed as a Search Operator?

• I took a look at the operator documentation. They still have the "+" operator but the how to use it says "Search for Google+ pages or blood types Examples: +Chrome or AB+". I guess that now even less people are using it. ;-)
– DaL
Commented Jan 11, 2017 at 8:43
• I added a link for that story to the answer. Commented Jan 11, 2017 at 10:07
• Interesting story. I wonder what will happen if Google+ will be renamed or removed.
– DaL
Commented Jan 11, 2017 at 10:17
• - still works to exclude terms I believe Commented Jan 17, 2017 at 23:30