Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword Search Error #3897

Open
cwberardi opened this issue Aug 23, 2023 · 0 comments
Open

Keyword Search Error #3897

cwberardi opened this issue Aug 23, 2023 · 0 comments

Comments

@cwberardi
Copy link

The API returns the same results regardless of quotes used in keywords.

Working example, where "machine learning" is used to call api/v2/download/count/ endpoint:

import requests
import json

reqUrl = "https://api.usaspending.gov/api/v2/download/count/"

headersList = {
 "Accept": "application/json",
 "Content-Type": "application/json" 
}

payload = json.dumps({
    "filters": {
        "keywords": [
            "machine learning"
        ]
      
    }
})

response = requests.request("POST", reqUrl, data=payload,  headers=headersList)

print(response.text)

API Response, which treats the query as "machine"&"learning"

{
  "calculated_transaction_count": 23690,
  "maximum_transaction_limit": 500000,
  "transaction_rows_gt_limit": false,
  "messages": [
    "For searches, time period start and end dates are currently limited to an earliest date of 2007-10-01.  For data going back to 2000-10-01, use either the Custom Award Download feature on the website or one of our download or bulk_download API endpoints as listed on https://api.usaspending.gov/docs/endpoints."
  ]
}

Working example using escaped quotes for ""machine learning"":

reqUrl = "https://api.usaspending.gov/api/v2/download/count/"

headersList = {
 "Accept": "application/json",
 "Content-Type": "application/json" 
}

payload = json.dumps({
    "filters": {
        "keywords": [
            "\"machine learning\""
        ]
      
    }
})

response = requests.request("POST", reqUrl, data=payload,  headers=headersList)

print(response.text)

API Response, which also treats the query as "machine" and "learning"

{
  "calculated_transaction_count": 23690,
  "maximum_transaction_limit": 500000,
  "transaction_rows_gt_limit": false,
  "messages": [
    "For searches, time period start and end dates are currently limited to an earliest date of 2007-10-01.  For data going back to 2000-10-01, use either the Custom Award Download feature on the website or one of our download or bulk_download API endpoints as listed on https://api.usaspending.gov/docs/endpoints."
  ]
}

Working example, where "'machine learning'" is used to call api/v2/download/count/ endpoint:

reqUrl = "https://api.usaspending.gov/api/v2/download/count/"

headersList = {
 "Accept": "application/json",
 "Content-Type": "application/json" 
}

payload = json.dumps({
    "filters": {
        "keywords": [
            "'machine learning'"
        ]
      
    }
})

response = requests.request("POST", reqUrl, data=payload,  headers=headersList)

print(response.text)

API Response, I can't explain this behavior. The results are much narrower than 'machine learning'

{
  "calculated_transaction_count": 8,
  "maximum_transaction_limit": 500000,
  "transaction_rows_gt_limit": false,
  "messages": [
    "For searches, time period start and end dates are currently limited to an earliest date of 2007-10-01.  For data going back to 2000-10-01, use either the Custom Award Download feature on the website or one of our download or bulk_download API endpoints as listed on https://api.usaspending.gov/docs/endpoints."
  ]
}

This API behavior isn't well documented. I'm not sure if this is user error or an issue with the API. I would appreciate an explanation of the behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant