Skip to content
Advertisement

AND/OR Operator Precedence in Google Search

I need to do an advanced Google search, using their SiteSearch API. I’m currently using a string of the following format that is sent via curl to my search engine:

$search_url = "http://www.google.com/search?start=0&num=20&as_qdr=" . $as_qdr . "&q=" . $q . "&sort=date&client=google-csbe&output=xml_no_dtd&cx=" . $cx;

The problem is that my query needs to be of the form:

(“MY SENTENCE” AND “JOHN DOE”) OR “MIKE TYSON”

Unfortunately, I’m unable to find anything in Google Documentations to replace the usual sql parenthesis. I have tried using the parenthesis itself but although most results seem accurate, some of the results do not really match the query. For example, they contain “MY SENTENCE” and “MIKE TYSON”, but not JOHN DOE.

Is it even possible to do such complicated queries in Google?

Edit: I just forgot to mention that I tried the parenthesis directly on google.com (not using the API), for my testing.

Advertisement

Answer

According to the Google Guide website, which is not affiliated with Google, you can use a mix of both, the OR operator (alternatively |) and the double quotes " as a group compound, to achieve what you wanted, it’s all described in this article.
Further the whole Crafting Your Query article is also interesting to learn how to get the most of Google’s possibilities when using their search.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement