Skip to content

Commit

Permalink
Merge pull request #542 from keko24/main
Browse files Browse the repository at this point in the history
Fixed an issue where search_pubs returns an empty response when only a single publication exists for the query.
  • Loading branch information
arunkannawadi authored Jul 3, 2024
2 parents c6b579d + 2cd59b3 commit 568d4ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
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')

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

0 comments on commit 568d4ad

Please sign in to comment.