Fixed Gutenberg-store search issue (missing author names)

Collected works may lack the author name field, and its HTML div. This
interrupted the search results processing.

For example, searching on title or author using "erasmus" yielded no or
two results out of 25 max.

- Title search now works as expected.
- Author search omits discussed results. Apparently at a later stage a
match is required between 's.author' and the query.
This commit is contained in:
William Ouwehand 2021-04-29 16:44:09 +02:00
parent e5654c1c4f
commit dfca7b5721

View File

@ -52,7 +52,10 @@ def search(query, max_results=10, timeout=60, write_raw_to=None):
a = next(CSSSelect('a.link', li)) a = next(CSSSelect('a.link', li))
s.detail_item = absurl(a.get('href')) s.detail_item = absurl(a.get('href'))
s.title = etree.tostring(next(CSSSelect('span.title', li)), method='text', encoding='unicode').strip() s.title = etree.tostring(next(CSSSelect('span.title', li)), method='text', encoding='unicode').strip()
s.author = etree.tostring(next(CSSSelect('span.subtitle', li)), method='text', encoding='unicode').strip() try:
s.author = etree.tostring(next(CSSSelect('span.subtitle', li)), method='text', encoding='unicode').strip()
except StopIteration:
s.author = ""
for img in CSSSelect('img.cover-thumb', li): for img in CSSSelect('img.cover-thumb', li):
s.cover_url = absurl(img.get('src')) s.cover_url = absurl(img.get('src'))
break break