Being able to find articles when parameters have values of None
Closed this issue · 1 comments
Hi ADSABS team!
I am using your api in a simple program to search for articles in your database. However, whenever I try to search up an article and do not have specific parameters, then the result which should be coming doesn't come. Here is my querystring -
querystring = {"q": "first_author:" + first_author + ",year:" + year + ", volume:" + volume + ",
page:" + pages[0],
"fl": "bibcode,page,desc,title,author,volume"}
Let's say that I do not know the information for the volume and that has a value of None. If I was to send that request, then the API wouldn't return the correct response. How do I make it so that even I do not have the values for one or two parameters, then it would still be able to send a request and correctly give a response and find a doc.
Hi Rudra,
The best way to handle this would be to use an if statement when building your query string. Something like this (assuming you're using Python):
query = 'first_author:' + first_author + ' year:'+ year
if volume:
query += ' volume:' + volume
if page:
query += ' page:' + page
There are potentially some other ways you could write this, but we're limited by the fact that if a record doesn't have a volume/page, then it doesn't usually have that field even associated with the record in the database (so you couldn't just do a wildcard search on the volume/page, for example). And if you're getting into that level of detail anyway, you might as well just modify the query string based on the fields you do have, as I've outlined above.
Hope this helps!