Skip to content
NewsDataHub NewsDataHub Learning Center

How Do I Search and Filter News Data? Boolean Operators and Advanced Filtering with NewsDataHub

Learn how to use q with GET /v1/news and GET /v1/top-news to build precise searches (AND/OR/NOT, quoted phrases, grouping), combine them with topic/source/date/language/country filters and exclude_topic, and run authenticated curl examples.

Searching and filtering news data is an important part of many data-driven applications. Whether you’re building a news aggregator, a sentiment analysis tool, or a research project, being able to efficiently and accurately sift through large volumes of news data is crucial. NewsDataHub is a news API that provides powerful search and filtering capabilities to harness its extensive news database. In this article, we’ll dive into the API’s advanced search features, exploring how to use the q parameter along with AND, OR, NOT operators, topic filtering, source filtering, and date range queries.

  • Volume and velocity: News flows continuously from thousands of sources. Without precise search, you drown in noise and miss what matters.
  • Precision over guesswork: Boolean operators and phrase matching let you ask exact questions and get focused answers.
  • Composable filters: Combine search with topic, source, language, country, and time windows to drill into the exact slice you need.

Common scenarios where precision search pays off:

  • Politics and policy tracking: Narrow your feed to political reporting by focusing on the politics topic. This helps policy teams, journalists, and civic groups follow elections, legislation, and government actions without wading through unrelated stories.
  • Remove irrelevant subtopics: When you care about technology but not gaming, exclude gaming to keep product launches, chips, cloud, and enterprise coverage front and center. Use the exclude_topic parameter name to describe what you want to filter out.
  • Language‑specific monitoring: Analysts and local teams can track Spanish‑language articles to capture regional sentiment and coverage that may not appear in English.
  • Country‑based sourcing: Compliance and regional teams can limit sources to a specific country (for example, US publishers) to align with jurisdictional requirements or audience focus.
  • Clear intent with boolean logic: AND means both must be present, OR means either is acceptable, NOT removes mentions you want to exclude. For example, a research analyst might look for articles that mention “quantum computing” and IBM together, accept either IBM or Google when surveying the competitive set, and exclude rumor to keep signals clean.
  • Business outcomes: Product teams build personalized feeds; finance teams follow companies and earnings; PR teams monitor competitors and press releases; security teams watch for “data breach” or “lawsuit” signals; academics study themes like “quantum computing” with precise phrases to avoid drift.

NewsDataHub is a news API that aggregates and normalizes articles and article headlines from a variety of sources including mainstream media, digital native publications, press releases, and more. It supports full‑text search with boolean and phrase operators, rich filters (topic, source, language, country, political_leaning, source_type, and others), and cursor‑based pagination. Access is authenticated with an API key (in X-API-Key header) and behavior varies by subscription tier — see our docs about how to authenticate.

  • GET /v1/news — Full article stream with historical access and rich filters. Ideal for precise querying across broader coverage windows.
  • GET /v1/top-news — Curated mainstream coverage from the last 24–72 hours; supports q but results come from a narrower, time‑boxed set.

Note: GET /v1/news/{article_id}/related does not accept q (it uses similarity matching instead).

All requests must include your API key in the X-API-Key header — see our docs about how to authenticate. A convenient pattern is to store it in an environment variable and reference it in every call:

export NEWSDATAHUB_API_KEY='YOUR_API_KEY_HERE'

Then add the header to curl:

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing"' \
--data-urlencode 'per_page=5'

The q parameter provides full‑text search with boolean and phrase operators across title, description, and content.

Key rules at a glance:

  • Spaces behave like OR: Google earningsGoogle OR earnings (default operator is OR)
  • Require both terms with AND: "quantum computing" AND IBM
  • Exclude terms with NOT or a leading minus: ("quantum computing" AND IBM) NOT Google or "quantum computing" AND IBM -Google
  • Exact phrases must be wrapped in double quotation marks: "quantum computing"
  • Group with parentheses: "quantum computing" AND (IBM OR Google)
  • q=Google — single word query

How it works: Returns articles that mention the word “Google” in the title, description, or content (matching is generally case‑insensitive, so “google” also matches).

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=Google' \
--data-urlencode 'per_page=5'
  • q=“quantum computing” — exact phrase match (phrases require double quotes)

How it works: Requires the exact phrase “quantum computing” (the words together, in this order) to appear in the searched fields. Use double quotation marks to enforce phrase matching.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing"' \
--data-urlencode 'per_page=5'
  • q=“quantum computing” AND IBM — phrase plus a required term

How it works: The article must contain the exact phrase “quantum computing” and also mention “IBM” (anywhere in title/description/content). AND combines both conditions.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing" AND IBM' \
--data-urlencode 'per_page=5'
  • q=(“quantum computing” AND IBM) NOT Google — exclude results mentioning Google

How it works: Must include the phrase “quantum computing” and mention “IBM”, and must not mention “Google”. The NOT clause removes any article that mentions Google in the searched fields. Parentheses keep the include‑conditions together.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
--data-urlencode 'q=("quantum computing" AND IBM) NOT Google' \
--data-urlencode 'per_page=5'
  • q=“quantum computing” AND (IBM OR Google) — group alternatives with OR

How it works: Requires the phrase “quantum computing” and at least one of the terms IBM or Google. Parentheses apply OR to the alternatives while AND ties them to the phrase.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing" AND (IBM OR Google)' \
--data-urlencode 'per_page=5'
  • q=“quantum computing” AND (IBM NOT Amazon) — mix AND with NOT inside a group

How it works: Requires the phrase “quantum computing” and also requires IBM while excluding Amazon. The grouped clause effectively means IBM AND NOT Amazon.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing" AND (IBM NOT Amazon)' \
--data-urlencode 'per_page=5'
  • q=“quantum computing” OR “artificial intelligence” — match either phrase

How it works: Matches documents that contain either the phrase “quantum computing” or the phrase “artificial intelligence”. Use OR to broaden recall across multiple phrases.

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q="quantum computing" OR "artificial intelligence"' \
--data-urlencode 'per_page=5'

These queries power live news feeds in production environments, demonstrating advanced search and filtering patterns. Each example links to a working feed that updates every 60 seconds.

Track data breaches, ransomware attacks, and security threats with precision:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=(cybersecurity OR "cyber attack" OR "data breach" OR ransomware) AND (threat OR attack OR breach OR hack)' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: Security teams monitoring global threat landscape Live feed: https://newsdatahub.com/live/cybersecurity

Monitor workforce reductions and hiring freezes across industries:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=(layoffs OR "job cuts" OR "hiring freeze" OR "workforce reduction")' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: HR professionals tracking workforce trends Live feed: https://newsdatahub.com/live/layoffs

Track logistics issues, shortages, and supply chain bottlenecks:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=("supply chain" OR logistics OR shipping OR freight) AND (shortage OR delay OR disruption OR bottleneck OR crisis)' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: Supply chain managers monitoring bottlenecks Live feed: https://newsdatahub.com/live/supply-chain

Monitor fraud cases, scams, and financial crime:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=(fraud OR scam OR "financial crime" OR "money laundering" OR embezzlement)' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: Financial institutions tracking fraud schemes Live feed: https://newsdatahub.com/live/fraud

Track cloud failures, platform downtime, and service disruptions:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=("internet outage" OR "cloud outage" OR "platform down" OR "service disruption" OR downtime)' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: IT operations tracking service disruptions Live feed: https://newsdatahub.com/live/tech-outages

Monitor lawsuits, regulatory actions, and legal penalties:

Terminal window
curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'q=(lawsuit OR "class action" OR litigation OR "regulatory action" OR antitrust OR settlement OR "legal penalty")' \
--data-urlencode 'search_in=title' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=20'

Use case: Legal departments monitoring industry litigation Live feed: https://newsdatahub.com/live/corporate-legal

Explore 31+ more production queries: Live Feeds Repository — including geopolitical monitoring, industry-specific tracking, regional coverage, and market intelligence feeds.

Filter by topic using the topic parameter. Provide one or many values (comma‑separated or repeated). For example, topic=technology,politics returns articles tagged with either technology or politics.

Example:

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'topic=technology' \
--data-urlencode 'topic=finance' \
--data-urlencode 'language=en' \
--data-urlencode 'per_page=5'

Filter by source/title using the source parameter (comma‑separated or repeated). For example, using repeated params: source=The Botswana Gazette&source=CBS News returns articles from either The Botswana Gazette or CBS News.

Note: Use the source name exactly as it appears in API responses.

  • For news endpoints, match the source_title field (for example, “ABC News”).
  • For the sources endpoint, use the title value (for example, “+972 Magazine”).

Example (per_page=5, repeated params):

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'source=The Botswana Gazette' \
--data-urlencode 'source=CBS News' \
--data-urlencode 'per_page=5'

Restrict results with start_date and/or end_date (format YYYY-MM-DD). Example: start_date=2024-09-01&end_date=2024-09-30. Note: free tier requests include a 48‑hour freshness delay.

Example (per_page=5):

curl -G https://api.newsdatahub.com/v1/news \
-H "X-API-Key: $NEWSDATAHUB_API_KEY" \
-H "User-Agent: newsdatahub-search-filtering-guide/1.0-curl" \
--data-urlencode 'start_date=2025-09-01' \
--data-urlencode 'end_date=2025-09-30' \
--data-urlencode 'per_page=5'

Remember to check the official documentation for current rate limits and request quotas.

The NewsDataHub API provides robust and versatile search and filtering capabilities that can cater to various use cases. With a good understanding of how to use the q parameter, AND, OR, NOT operators, and the various filtering options, you can construct detailed queries that return the precise data you’re looking for.

Remember that these examples are just the tip of the iceberg when it comes to what you can achieve with NewsDataHub’s search and filtering capabilities. Check out the official API documentation for more detailed information and to stay updated on rate limits and request quotas.

Now, you’re well-equipped to start building advanced queries to extract the news data you need. Happy querying!

  • Do I need to specify a keyword for /search?

    Yes. The /search endpoint requires a q parameter with at least one keyword. Use /top endpoint if you want to browse without keyword filtering.

  • How do I search for exact phrases?

    Wrap phrases in double quotes: q="climate change". This returns only articles containing that exact phrase.

  • Can I use boolean operators (AND, OR, NOT)?

    Yes. Use AND, OR, and NOT for complex queries: q="electric cars" AND (Tesla OR Rivian) NOT recalled.

  • How far back does the search history go?

    NewsDataHub maintains a rolling archive. Free tier: 30 days. Paid tiers: 90 days to 1 year depending on plan. Check your plan details for specifics.

  • Can I sort results by relevance or date?

    Results are sorted by relevance by default. Use date range filters (from, to) to narrow by time, but sorting order is always relevance-first.

Olga S.

Founder of NewsDataHub — Distributed Systems & Data Engineering

Connect on LinkedIn