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.
- Always URL-encode your query string
- Use quotes around special characters
- Combine operators for precise results
Basic Search
The simplest way to search is to provide keywords. The API will return articles containing those keywords.
covid-19) is treated as a literal character, not as negation. To exclude a term, use the NOT operator instead.Phrase Search
Use quotation marks to search for an exact phrase. This ensures the words appear together in the specified order.
AND Operator
By default, spaces between words act as AND operators. You can also use AND explicitly.
OR Operator
Use OR to match articles containing either term. To control precedence, group terms with parentheses, for example iphone AND (13 OR 14).
NOT Operator
Use NOT to exclude articles containing specific terms.
Combining Operators
You can combine operators for complex queries. Use parentheses to control precedence.
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.
Unsupported Operators
q: field scoping (field:value), regular expressions (/.../), wildcards (* and ?), fuzzy and proximity searches (~), boosting (^), and range syntax ([a TO b]).Examples of valid queries
| Query | Expected Result |
|---|---|
google | News articles that contain the word google |
google OR android | News 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 google | News articles that contain the word android but not the word google |
technology&ai_sentiment=positive | The q=technology query combined with the separate ai_sentiment=positive parameter (not part of q) |
Apple&ai_entity_type=ORG | The q=Apple query combined with the separate ai_entity_type=ORG parameter (not part of q) |
climate&ai_entity_name=United Nations | The q=climate query combined with the separate ai_entity_name=United Nations parameter (not part of q) |