-2

Is there some kind of query language one can use in Bing Search API News to get, for example, only news that contain in their title some words/phrases? Is there AND, OR, near, etc. that could be used? You can see the operators here, which I thought would be working: https://msdn.microsoft.com/en-us/library/ff795620.aspx

I am talking right now about version 5 and version 7 of the API.

Here's the code I wrote to try this out:

# below query is want I would like to have, which doesn't work
query_words = ['announce* near:4 win']

headers = {'Ocp-Apim-Subscription-Key': 'xxxx'}

b = 'https://api.cognitive.microsoft.com/bing/v5.0/news/search'

for w in query_words:
    params = {"q": w, "count": "5", "mkt": "en-US", "category": "business", "freshness": "day"}

    res = requests.get(b, params=params, headers=headers)

    if res.status_code == 200:
        articles = json.loads(res.content)
Nicolas R
  • 13,812
  • 2
  • 28
  • 57
elena
  • 3,740
  • 5
  • 27
  • 38

2 Answers2

0

Unfortunately, for Bing News Search API v5/v7, there is not any operators like your linked for Bing API v2.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • How do you know that? If you check here: https://learn.microsoft.com/en-us/rest/api/cognitiveservices/bing-news-api-v5-reference and search for Bing Advanced Operators on that page, you'll see that the it references to that same page. – elena Aug 10 '17 at 13:27
  • @elena Please see the item tree, the Bing Advanced Operatores is under the root of Bing API v2 which is old version, not Bing News Search API. – Peter Pan Aug 14 '17 at 08:45
  • If you search on the page https://learn.microsoft.com/en-us/rest/api/cognitiveservices/bing-news-api-v5-reference for Bing Advanced Operators, you'll find it. – elena Aug 23 '17 at 08:25
0

It works, you need to append the operator to query (the q parameter). I tried on curl with this query:

curl -v -X GET "https://api.cognitive.microsoft.com/bing/v7.0/news/search?q=seattle%2Ccontains:Bellevue" -H "Ocp-Apim-Subscription-Key: YOUR_KEY"

and it modifies results to include "Bellevue" in description. Similarly, site: parameter is also working. Seems the operators on the page you mentioned are applicable to v7.

Ronak
  • 751
  • 5
  • 10