Skip to content

Commit

Permalink
Merge pull request #87 from golnazads/master
Browse files Browse the repository at this point in the history
couple of modifications for myads:
  • Loading branch information
golnazads committed Nov 8, 2019
2 parents a4e7e39 + 30af997 commit 166e69e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
22 changes: 17 additions & 5 deletions tugboat/tests/tests_unit/test_search_redirect.py
Expand Up @@ -1010,7 +1010,7 @@ def test_myads_query(self):
req.prepare()
req.mimetype = None

# Daily arXiv query with db_key DAILY_PRE => no OR
# Daily arXiv query with db_key DAILY_PRE => OR
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'DAILY_PRE'), ('qform', 'PRE'),
('arxiv_sel', 'astro-ph'), ('start_year', '2019'),
('start_entry_day', '15'), ('start_entry_mon', '10'), ('start_entry_year', '2019'),
Expand All @@ -1019,10 +1019,10 @@ def test_myads_query(self):
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('bibstem:arxiv ((arxiv_class:astro-ph.*) +"nuclear star cluster") entdate:["2019-10-15:00:00" TO 2019-10-16] pubdate:[2019-00 TO *]') +
self.assertEqual('q=' + urllib.quote('bibstem:arxiv ((arxiv_class:astro-ph.*) OR +"nuclear star cluster") entdate:["2019-10-15:00:00" TO 2019-10-16] pubdate:[2019-00 TO *]') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Daily arXiv query with anything other than DAILY_PRE => OR
# Daily arXiv query with db_key other than DAILY_PRE => no OR
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'PRE'), ('qform', 'PRE'),
('arxiv_sel', 'astro-ph'), ('start_year', '2019'),
('start_entry_day', '15'), ('start_entry_mon', '10'), ('start_entry_year', '2019'),
Expand All @@ -1031,7 +1031,7 @@ def test_myads_query(self):
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('bibstem:arxiv ((arxiv_class:astro-ph.*) OR +"nuclear star cluster") entdate:["2019-10-15:00:00" TO 2019-10-16] pubdate:[2019-00 TO *]') +
self.assertEqual('q=' + urllib.quote('bibstem:arxiv ((arxiv_class:astro-ph.*) +"nuclear star cluster") entdate:["2019-10-15:00:00" TO 2019-10-16] pubdate:[2019-00 TO *]') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly citations query
Expand All @@ -1043,7 +1043,7 @@ def test_myads_query(self):
self.assertEqual('q=' + urllib.quote('citations(author:"LOCKHART, KELLY")') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly authors query
# Weekly authors query with db_key other than PRE => no prefix
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'AST'),
('author', 'LU, JESSICA\r\nHOSEK, MATTHEW\r\nKEWLEY, LISA\r\nACCOMAZZI, ALBERTO\r\nKURTZ, MICHAEL'),
('start_entry_day', '26'), ('start_entry_mon', '9'), ('start_entry_year', '2019'),
Expand All @@ -1057,6 +1057,18 @@ def test_myads_query(self):
'&fq=%7B!type%3Daqp%20v%3D%24fq_database%7D&fq_database=(database%3A%22astronomy%22)' +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly authors query with db_key PRE => add prefix `bibstem:arxiv `
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'PRE'),
('author', 'LU, JESSICA\r\nHOSEK, MATTHEW\r\nKEWLEY, LISA\r\nACCOMAZZI, ALBERTO\r\nKURTZ, MICHAEL'),
('start_entry_day', '26'), ('start_entry_mon', '9'), ('start_entry_year', '2019'),
('end_entry_day', '18'), ('end_entry_mon', '10'), ('end_entry_year', '2019'),
('start_year', '2019')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('bibstem:arxiv author:"LU, JESSICA" OR author:"HOSEK, MATTHEW" OR author:"KEWLEY, LISA" OR author:"ACCOMAZZI, ALBERTO" OR author:"KURTZ, MICHAEL" entdate:["2019-09-26:00:00" TO 2019-10-18] pubdate:[2019-00 TO *]') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly keyword (recent papers) query
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'AST'),
('title', '"nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU'),
Expand Down
26 changes: 14 additions & 12 deletions tugboat/views.py
Expand Up @@ -350,7 +350,7 @@ def translate_myads_queries(self, args):

if query_type == 'PAPERS':
qform = args.pop('qform', None)
# Daily arXiv query
# Daily arXiv query (#1)
if qform:
arxiv_sel = args.pop('arxiv_sel', None)
title_str = args.pop('title', None)
Expand All @@ -361,9 +361,9 @@ def translate_myads_queries(self, args):
# if all entries are valid include them, oring them
arxiv_class = '(' + ' OR '.join(['arxiv_class:' + c + '.*' for c in arxiv_sel.split(',')]) + ')'
title = self.translate_title_for_myads(title_str)
# OR arxiv classes and title if any db_key other than DAILY_PRE,
# OR arxiv classes and title if db_key is DAILY_PRE,
# otherwise leave empty which is going to be AND
add_or = ' ' if args.get('db_key', 'DAILY_PRE') == 'DAILY_PRE' else ' OR '
add_or = ' OR ' if args.get('db_key', 'DAILY_PRE') == 'DAILY_PRE' else ' '
daily_arxiv_query = 'bibstem:arxiv ({arxiv_class}{add_or}{title}) entdate:["{date_start}:00:00" TO {date_end}] pubdate:[{start_year}-00 TO *]'
daily_arxiv_query = daily_arxiv_query.format(arxiv_class=arxiv_class, add_or=add_or, title=title,
date_start=date_start, date_end=date_end,
Expand All @@ -381,23 +381,25 @@ def translate_myads_queries(self, args):
date_end = self.translate_entry_date_end(args)
start_year = args.pop('start_year', None)

# if author is filled and title is empty then it is Weekly authors query
# if author is filled and title is empty then it is Weekly authors query (#3)
if authors_str and not title_str:
if start_year:
if start_year and date_start and date_end:
authors = self.classic_field_to_array(authors_str)
author_query = ' OR '.join(['author:' + x for x in authors])
weekly_authors_query = '{author_query} entdate:["{date_start}:00:00" TO {date_end}] pubdate:[{start_year}-00 TO *]'
weekly_authors_query = weekly_authors_query.format(author_query=author_query,
arxiv_addition = 'bibstem:arxiv ' if args.get('db_key', None) == 'PRE' else ''
weekly_authors_query = '{arxiv_addition}{author_query} entdate:["{date_start}:00:00" TO {date_end}] pubdate:[{start_year}-00 TO *]'
weekly_authors_query = weekly_authors_query.format(arxiv_addition=arxiv_addition,
author_query=author_query,
date_start=date_start, date_end=date_end,
start_year=start_year)
self.translation.search.append(urllib.quote(weekly_authors_query))
self.translation.sort = urllib.quote('score desc')
else:
self.translation.error_message.append('MISSING_REQUIRED_PARAMETER')

# if title is filled and author is empty then it is Weekly keyword (recent papers) query
# if title is filled and author is empty then it is Weekly keyword (recent papers) query (#4)
elif title_str and not authors_str:
if start_year:
if start_year and date_start and date_end:
title = self.translate_title_for_myads(title_str)
weekly_keyword_query = '{title} entdate:["{date_start}:00:00" TO {date_end}] pubdate:[{start_year}-00 TO *]'
weekly_keyword_query = weekly_keyword_query.format(title=title,
Expand All @@ -412,7 +414,7 @@ def translate_myads_queries(self, args):
elif authors_str and title_str:
self.translation.error_message.append('UNRECOGNIZABLE_VALUE')

# Weekly citations query
# Weekly citations query (#2)
elif query_type == 'CITES':
authors_str = args.pop('author', None)
if authors_str:
Expand All @@ -423,7 +425,7 @@ def translate_myads_queries(self, args):
else:
self.translation.error_message.append('MISSING_REQUIRED_PARAMETER')

# Weekly keyword (popular papers) query
# Weekly keyword (popular papers) query (#5)
elif query_type == 'ALSOREADS':
title_str = args.pop('title', None)
if title_str:
Expand All @@ -434,7 +436,7 @@ def translate_myads_queries(self, args):
else:
self.translation.error_message.append('MISSING_REQUIRED_PARAMETER')

# Weekly keyword (most cited) query
# Weekly keyword (most cited) query (#6)
elif query_type == 'REFS':
title_str = args.pop('title', None)
if title_str:
Expand Down

0 comments on commit 166e69e

Please sign in to comment.