Query Syntax

Understand the query syntax to search for news articles effectively

AllNewsAPI supports powerful query syntax that allows you to search for news articles with precision. Learn how to use operators to refine your searches.

Info
  • Always URL-encode your query string
  • Use quotes around special characters
  • Combine operators for precise results

The simplest way to search is to provide keywords. The API will return articles containing those keywords.

Basic Search
Tip
A hyphen inside a term (for example covid-19) is treated as a literal character, not as negation. To exclude a term, use the NOT operator instead.

Use quotation marks to search for an exact phrase. This ensures the words appear together in the specified order.

Phrase Search

AND Operator

By default, spaces between words act as AND operators. You can also use AND explicitly.

AND Operator

OR Operator

Use OR to match articles containing either term. To control precedence, group terms with parentheses, for example iphone AND (13 OR 14).

OR Operator

NOT Operator

Use NOT to exclude articles containing specific terms.

NOT Operator

Combining Operators

You can combine operators for complex queries. Use parentheses to control precedence.

Combined Operators

AI Filtering

AI filters such as ai_sentiment, ai_entity_name, and ai_entity_type are separate query-string parameters, not operators inside q. Add them to the request URL alongside q to narrow results by sentiment, entity name, or entity type.

Sentiment Filter
Combined AI Filters
Entity Name Filter

Unsupported Operators

Warning
For safety, some advanced Lucene features are intentionally disabled and are ignored if included in q: field scoping (field:value), regular expressions (/.../), wildcards (* and ?), fuzzy and proximity searches (~), boosting (^), and range syntax ([a TO b]).

Examples of valid queries

QueryExpected Result
googleNews articles that contain the word google
google OR androidNews articles that contain the word google or the word android
"google android"News articles that contain the word google android in the same exact order
"windows 8" AND "windows 10"News articles that contain both words: windows 8 and windows 10
iphone AND (13 OR 14)News articles that contain the word Iphone and one of 13 or 14
android NOT googleNews articles that contain the word android but not the word google
technology&ai_sentiment=positiveThe q=technology query combined with the separate ai_sentiment=positive parameter (not part of q)
Apple&ai_entity_type=ORGThe q=Apple query combined with the separate ai_entity_type=ORG parameter (not part of q)
climate&ai_entity_name=United NationsThe q=climate query combined with the separate ai_entity_name=United Nations parameter (not part of q)