Skip to main content
The q parameter is the heart of every Custom Search API request. Everything you type into it — individual keywords, quoted phrases, boolean logic, and wildcards — directly shapes which pages Google considers and which it discards. This page covers every syntax feature available in q, plus the three companion API parameters (exactTerms, excludeTerms, orTerms) that give you additional programmatic control over inclusion and exclusion.

Basic keyword queries

By default, Google treats multiple keywords as an implicit AND: every term must appear somewhere in the document for it to qualify as a result. Keyword order does not matter, but all terms must be present.
URL-encode your query string. Replace spaces with + or %20. Most HTTP client libraries handle this automatically when you pass q as a parameter rather than embedding it in the raw URL string.

Phrase search with quotation marks

Wrap terms in double quotes to require an exact phrase — the words must appear adjacent and in the specified order.
Use phrase search when individual words are common but their combination is specific — for example, "climate change adaptation" vs. climate change adaptation (which would also match pages about climate adaptation that don’t mention change).

Boolean operators

AND is the default — you don’t need to write it. Separate keywords with spaces and Google requires all of them.

Grouping with parentheses

Use parentheses to control the logical evaluation order when you mix OR with other terms, just as you would in a mathematical expression.
Parentheses are a hint to Google’s query parser but not universally enforced in all scenarios. For strict inclusion/exclusion logic, combine parentheses with the exactTerms, excludeTerms, and orTerms API parameters described below.

Wildcard (*)

The asterisk (*) acts as a wildcard that matches any word or sequence of words within a phrase. It is most useful inside quoted phrases to fill in an unknown word.
The wildcard works within quoted phrases. Outside quotes, * has no special behavior and is treated as a regular character or ignored. Use it when you want to find a well-known phrase but are unsure of one word.

API parameters for programmatic filtering

In addition to inline syntax in q, the API exposes three dedicated parameters that give you clean, programmatic control over term inclusion and exclusion — useful when your query strings are generated dynamically.
exactTerms — Requires every result to contain a specific phrase. This is the API-parameter equivalent of adding a quoted phrase to q, but it is applied as an additional mandatory constraint on top of whatever is already in q.
string
A phrase that must appear verbatim in every returned document. Only one phrase is supported per request.
When to use it: Use exactTerms when your application generates queries programmatically and you want to guarantee that a specific phrase appears in every result without embedding it directly in the q string.

Combining q syntax with API parameters

You can layer all three API parameters on top of q in the same request. Google applies them additionally — q is evaluated first, then exactTerms adds a required phrase, excludeTerms strips unwanted documents, and orTerms adds an OR constraint.
This request finds pages about renewable energy (solar or wind) that:
  • Must contain the phrase “cost reduction” (exactTerms)
  • Must not mention “nuclear” (excludeTerms)
  • Must mention at least one of “investment”, “funding”, or “grant” (orTerms)

Quick-reference syntax table

Practical examples