How to use boolean operators
Refine queries with AND, OR, and NOT
Overview
Boolean operators are powerful tools that allow you to create more complex and precise search queries. These operators help you filter news articles to find the content you need.
News API v3 supports three main boolean operators:
AND
: Ensures both terms are present in the search results.OR
: Allows for either term to be present.NOT
: Excludes terms from the search results.
Additionally, you can use parentheses ()
to group terms and create more
complex queries.
By combining these operators, you can significantly improve the relevance of your search results and find the most pertinent news articles for your needs.
Before you start
Before you begin, ensure you have:
- An active API key for NewsCatcher News API v3
- Basic knowledge of making API requests
- Python or another tool for making HTTP requests (e.g., cURL, Postman, or a programming language with HTTP capabilities)
Steps
- Construct your query using boolean operators.
When forming your query, use parentheses to group terms and operators. Here are some examples:
(bitcoin OR cryptocurrency) AND (investment OR trading)
"electric cars" NOT Tesla
("artificial intelligence" OR AI) AND healthcare NOT (Google OR Amazon OR Microsoft)
- Make an API request with your boolean query.
Use the /search
endpoint with your constructed query in the q
parameter.
Here is a code example in Python:
- Analyze the results.
The API returns a JSON response with the following structure:
- Refine your query as needed.
If you’re getting too many or too few results, adjust your query. Add more
specific terms with AND
, broaden your search with OR
, or exclude certain
topics with NOT
.
See also
Was this page helpful?