Advanced search queries

Datanews API has several special functions used for building advanced search queries. By default, provided search keywords will be tokenized as is and then will be used to search the news index. But, if you need to search for an exact phrase, or to find a specific combination of terms using boolean operators, then you could do that too.

These search queries use special symbols (e.g. +, |, -), each has its own semantic meaning. If you want to search for a phrase that includes, say +, then you have to escape it in the following way \+.


Exact match

To find an exact match of the phrase, you could wrap it into double quotes, e.g. "YOUR PHRASE" construct. See an example below.

Request
curl -XGET -G 'api.datanews.io/v1/news' --data-urlencode 'q="Europe throws new rule book at Google"' 
Response
{
  "status": 200,
  "numResults": 2,
  "hits": [
    {
      "url": "https://business.financialpost.com/technology/europe-throws-new-rule-book-at-google-tech-giants-to-loosen-market-grip",
      "source": "business.financialpost.com",
      "authors": [],
      "title": "Europe throws new rule book at Google, tech giants to loosen market grip",
      "pubDate": "2020-07-02T13:40:43+00:00",
      "country": "us",
      "language": "en",
      "description": "EU's new regulations could become a template for governments around the world looking to rein in Google, Apple, Amazon and Facebook",
      "imageUrl": "https://financialpostcom.files.wordpress.com/2020/07/tech.jpg",
      "content": "..."
    },
    ...
  ]
}

Boolean operators

Boolean operators can be used to search for different combination of keywords. Datanews supports following boolean operators:

  • + AND operator
  • | OR operator
  • - NOT operator
  • * operator at the end of term signifies prefix query
  • ( ... ) parentheses for grouping
Request
curl -XGET -G 'api.datanews.io/v1/news' --data-urlencode 'q=google+facebook+amazon' 
Response
{
  "status": 200,
  "numResults": 208,
  "hits": [
    {
      "url": "https://www.businessinsider.com/facebook-amazon-google-apple-ceos-testify-antitrust-hearings-2020-7",
      "source": "businessinsider.com",
      "authors": [
        "Isobel Asher Hamilton"
      ],
      "title": "Tim Cook, Mark Zuckerberg, Jeff Bezos, and Sundar Pichai will all testify before Congress in an antitrust hearing",
      "pubDate": "2020-07-02T10:25:16+00:00",
      "country": "us",
      "language": "en",
      "description": "Facebook, Amazon, and Google had all reportedly been confirmed for the antitrust hearing by mid-June, but Apple had stayed quiet.",
      "imageUrl": "https://i.insider.com/5cf657ec11e20538196144f4?width=1200&format=jpeg",
      "content": "..."
    },
    ...
  ]
}