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.
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 find articles containing either term. Note: OR takes precedence over AND.
NOT Operator
Use NOT to exclude articles containing specific terms.
Combining Operators
You can combine operators for complex queries. Use parentheses to control precedence.
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 |