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

Fixed an issue where search_pubs returns an empty response when only a single publication exists for the query. #542

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scholarly/publication_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _load_url(self, url: str):
# this is temporary until setup json file
self._soup = self._nav._get_soup(url)
self._pos = 0
self._rows = self._soup.find_all('div', class_='gs_r gs_or gs_scl') + self._soup.find_all('div', class_='gsc_mpat_ttl')
self._rows = self._soup.find_all('div', class_='gs_r gs_or gs_scl') + self._soup.find_all('div', class_='gs_r gs_or gs_scl gs_fmar') + self._soup.find_all('div', class_='gsc_mpat_ttl')
keko24 marked this conversation as resolved.
Show resolved Hide resolved

def _get_total_results(self):
if self._soup.find("div", class_="gs_pda"):
Expand All @@ -70,7 +70,7 @@ def _get_total_results(self):
match = re.match(pattern=r'(^|\s*About)\s*([0-9,\.\s’]+)', string=x.text)
if match:
return int(re.sub(pattern=r'[,\.\s’]',repl='', string=match.group(2)))
return 0
return len(self._rows)

# Iterator protocol

Expand Down
17 changes: 17 additions & 0 deletions test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,23 @@ def test_search_pubs(self):
titles = [p['bib']['title'] for p in pubs]
self.assertIn('Visual perception of the physical stability of asymmetric three-dimensional objects', titles)

def test_search_pubs_single_pub(self):
"""
As of Jun 24, 2024 there are is only one pub that fits the search term:
[Perception of physical stability and center of mass of 3D objects].

Check that it returns a proper result and the total results for that search term is equal to 1.
"""
pub = scholarly.search_single_pub("Perception of physical stability and center of mass of 3D objects")
pubs = list(scholarly.search_pubs("Perception of physical stability and center of mass of 3D objects"))
# Check that the first entry in pubs is the same as pub.
# Checking for quality holds for non-dict entries only.
for key in {'author_id', 'pub_url', 'num_citations'}:
self.assertEqual(pub[key], pubs[0][key])
for key in {'title', 'pub_year', 'venue'}:
self.assertEqual(pub['bib'][key], pubs[0]['bib'][key])
self.assertEqual(len(pubs), 1)

def test_search_pubs_total_results(self):
"""
As of September 16, 2021 there are 32 pubs that fit the search term:
Expand Down
Loading