-
Notifications
You must be signed in to change notification settings - Fork 85
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
adds Author advanced_search (w/ facets on birth + death date) #92
Conversation
params = {'name': name, 'birth_date': birth_date, 'death_date': death_date} | ||
paramstr = '+'.join(['%s:%s' % (k, v) for (k, v) in params.items() if v]) | ||
url = cls.OL.base_url + '/search/authors.json?limit=%s&q=%s' % (limit, paramstr) | ||
r = requests.get(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the params
arg with requests.get:
requests.get(cls.OL.base_url + '/search/authors.json', params={'limit': limit, ...})
This will also encode the url parameters.
[u'OL26320A]' | ||
|
||
Returns: | ||
List of Author olid from API if results, else None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: this doesn't return None
e.g. "\"January 5\"" | ||
You can also do something like "*1982*" | ||
(without quotes) to partial match on, e.g. year | ||
date_date (str) - The death date of the Author; same conditions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: date_date
r = requests.get(url) | ||
try: | ||
authors = r.json().get('docs', []) | ||
except requests.JSONDecodeError as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case when this could be thrown?
birth_date (str) - The birth date of the Author exactly as it | ||
appears in OL (e.g. "January 5, 2013"). | ||
Must be in quotes if the date is mult-terms, | ||
e.g. "\"January 5\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use single quote here so you don't have to escape the double quotes.
List of Author olid from API if results, else None | ||
""" | ||
params = {'name': name, 'birth_date': birth_date, 'death_date': death_date} | ||
paramstr = '+'.join(['%s:%s' % (k, v) for (k, v) in params.items() if v]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
query might be a better name for this; it'll get run pretty much directly on solr.
@@ -582,6 +582,41 @@ def get(cls, olid): | |||
bio=OpenLibrary.get_text_value(data.pop('bio', None)), | |||
**data) | |||
|
|||
@classmethod | |||
def advanced_search(cls, name=None, birth_date=None, death_date=None, limit=5): | |||
"""Searches for an Open Library authors using author API endpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: grammar
Can this be worked on to correct it based on @cdrini 's review? |
This PR closes #91
Description:
Even though an Author search method exists...
i.e.
ol = OpenLibrary();ol.Author.search(...)
It uses the autocomplete API which doesn't appear to support query by birth + death date. For now, to unblock @salman-bhai, this PR adds an
Author.advanced_search
which directly hits the Author json API endpoint and supports these additional facets.