nytimes / public_api_specs

The API Specs (in OpenAPI/Swagger) for the APIs available from developer.nytimes.com
http://developer.nytimes.com
Apache License 2.0
136 stars 40 forks source link

Article Search API Query Problem #59

Open hp0404 opened 3 years ago

hp0404 commented 3 years ago

Hi there!

I'm trying to use Article Search API to download articles that are relevant to this query: ("military" OR "soldier*" OR "air force" OR "navy" OR "army") AND ("threat*" OR "danger*" OR "fear*" OR "risk*")

But some entries are just random?


The code I used

import requests

apikey = ""

params = {
    "fq": '("military" OR "soldier*" OR "air force" OR "navy" OR "army") AND ("threat*" OR "danger*" OR "fear*" OR "risk*")',
    "begin_date": "20210101",
    "end_date": "20210601",
    "api-key": apikey,
    "page": 0
}
headers = {"Accept": "application/json"}
response = requests.get("https://api.nytimes.com/svc/search/v2/articlesearch.json", params=params, headers=headers).json()

for item in response["response"]["docs"]:
    print(item["abstract"])

# What happens to the nearly two million people in our nation’s prison system demonstrates who we are as a people.
# A look back at what has transpired in the year since Mr. Floyd’s murder reveals a country both struggling to confront it history # of racial division and continuing to succumb to it.
# A cease-fire between Israel and Hamas.
# Mr. Biden has spoken publicly about how he once sent Mr. Netanyahu a photograph with the inscription, “Bibi, I don’t agree with a damn thing you say, but I love you.”
# The move, which will require companies to report to the government any significant attacks, is a response to the Colonial Pipeline ransomware attacks.
# Mr. Protasevich, 26, is an exiled dissident whose reach drew an authoritarian ruler into a gambit that outraged Western governments.
# Israeli extremists have formed more than 100 new groups on the Facebook-owned encrypted messaging app in recent days to target attacks.
# A new kind of pandemic grief.
# After 11 days of intense fighting, Hamas and Israel began a cease-fire. Here is the arc of the conflict.
# An eviction in East Jerusalem lies at the center of a conflict that led to war between Israel and Hamas. But for millions of Palestinians, the routine indignities of occupation are part of daily life.
nyt-hughmandeville commented 2 years ago

The Article Search API searches the article body and some of the metadata fields (headline, byline, ...).

("military" OR "soldier" OR "air force" OR "navy" OR "army") AND ("threat" OR "danger" OR "fear" OR "risk")

I checked a few of the articles that you mentioned and their bodies contain the words in your query.

https://www.nytimes.com/2021/05/31/opinion/covid-new-york-state-prisons.html has the words soldier, threat, and fear.

https://www.nytimes.com/2021/05/25/us/george-floyd-protests-unrest-events-timeline.html has the words military, navy, soldier, threatens, fear.

https://www.nytimes.com/2021/05/18/us/politics/biden-netanyahu.html has the words military, air force, and threat.