Skip to content

Commit

Permalink
Merge pull request #90 from golnazads/master
Browse files Browse the repository at this point in the history
added to four of myads queries arxiv addition …
  • Loading branch information
golnazads authored Nov 20, 2019
2 parents 29bbbed + 029b4be commit 9f3eef8
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 16 deletions.
66 changes: 60 additions & 6 deletions tugboat/tests/tests_unit/test_search_redirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ def test_myads_query(self):
req.mimetype = None

# Daily arXiv query with db_key DAILY_PRE => OR
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'DAILY_PRE'), ('qform', 'PRE'),
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'DAILY_PRE'),
('arxiv_sel', 'astro-ph'), ('start_year', '2019'),
('start_entry_day', '15'), ('start_entry_mon', '10'), ('start_entry_year', '2019'),
('end_entry_day', '16'), ('end_entry_mon', '10'), ('end_entry_year', '2019'),
Expand All @@ -1023,7 +1023,7 @@ def test_myads_query(self):
'&sort=' + urllib.quote('score desc') + '/', search)

# Daily arXiv query with db_key other than DAILY_PRE => no OR
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'PRE'), ('qform', 'PRE'),
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'PRE'),
('arxiv_sel', 'astro-ph'), ('start_year', '2019'),
('start_entry_day', '15'), ('start_entry_mon', '10'), ('start_entry_year', '2019'),
('end_entry_day', '16'), ('end_entry_mon', '10'), ('end_entry_year', '2019'),
Expand All @@ -1041,7 +1041,7 @@ def test_myads_query(self):
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('citations(author:"LOCKHART, KELLY")') +
'&sort=' + urllib.quote('score desc') + '/', search)
'&sort=' + urllib.quote('entdate desc') + '/', search)

# Weekly authors query with db_key other than PRE => no prefix
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'AST'),
Expand All @@ -1057,16 +1057,16 @@ 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'),
# Weekly authors query with db_key PRE => add arxiv
req.args = MultiDict([('query_type', 'PAPERS'), ('db_key', 'PRE'), ('arxiv_sel', 'astro-ph'),
('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 *]') +
self.assertEqual('q=' + urllib.quote('bibstem:arxiv arxiv_class:astro-ph.* 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
Expand Down Expand Up @@ -1105,6 +1105,60 @@ 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 citations query with db_key PRE => add arxiv
req.args = MultiDict([('query_type', 'CITES'), ('db_key', 'PRE'), ('arxiv_sel', 'astro-ph'),
('author', 'LOCKHART, KELLY')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('citations((author:"LOCKHART, KELLY") bibstem:arxiv arxiv_class:astro-ph.*)') +
'&sort=' + urllib.quote('entdate desc') + '/', search)

# Weekly keyword (popular papers) query with db_key PRE => add arxiv
req.args = MultiDict([('query_type', 'ALSOREADS'), ('db_key', 'PRE'), ('arxiv_sel', 'astro-ph'),
('title', '"nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('trending(("nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU) bibstem:arxiv arxiv_class:astro-ph.*)') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly keyword (most cited) query with db_key PRE => add arxiv
req.args = MultiDict([('query_type', 'REFS'), ('db_key', 'PRE'), ('arxiv_sel', 'astro-ph'),
('title', '"nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('useful(("nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU) bibstem:arxiv arxiv_class:astro-ph.*)') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly citations query with db_key PRE => no arxiv classes specified, so no arxiv
req.args = MultiDict([('query_type', 'CITES'), ('db_key', 'PRE'),
('author', 'LOCKHART, KELLY')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('citations(author:"LOCKHART, KELLY")') +
'&sort=' + urllib.quote('entdate desc') + '/', search)

# Weekly keyword (popular papers) query with db_key PRE => no arxiv classes specified, so no arxiv
req.args = MultiDict([('query_type', 'ALSOREADS'), ('db_key', 'PRE'),
('title', '"nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('trending("nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU)') +
'&sort=' + urllib.quote('score desc') + '/', search)

# Weekly keyword (most cited) query with db_key PRE => no arxiv classes specified, so no arxiv
req.args = MultiDict([('query_type', 'REFS'), ('db_key', 'PRE'),
('title', '"nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU')])
req.args.update(self.append_defaults())
view = ClassicSearchRedirectView()
search = view.translate(req)
self.assertEqual('q=' + urllib.quote('useful("nuclear star cluster" OR ADS OR "supermassive black holes" OR M31 OR "Andromeda Galaxy" OR OSIRIS OR IFU)') +
'&sort=' + urllib.quote('score desc') + '/', search)

def test_myads_query_error(self):
"""test query_type"""
req = Request('get', 'http://test.test?')
Expand Down
38 changes: 28 additions & 10 deletions tugboat/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,15 @@ def translate_title_for_myads(self, value):
# go with regular tokenizer
return self.classic_field_to_string(value)[0].lstrip('*')

def arxiv_class_addition_myads_queries(self, args):
"""return arxiv query string for myads queries"""
arxiv_sel = args.pop('arxiv_sel', None)
if arxiv_sel and self.validate_arxiv_sel(arxiv_sel):
# if all entries are valid include them, oring them
arxiv_class = ' OR '.join(['arxiv_class:' + c + '.*' for c in arxiv_sel.split(',')])
return arxiv_class
return None

def translate_myads_queries(self, args):
"""return query string for the six different myads queries"""

Expand All @@ -362,7 +371,8 @@ def translate_myads_queries(self, args):
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])
arxiv_addition = 'bibstem:arxiv ' if args.get('db_key', None) == 'PRE' else ''
arxiv_class = self.arxiv_class_addition_myads_queries(args)
arxiv_addition = 'bibstem:arxiv %s '%arxiv_class if arxiv_class and 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,
Expand All @@ -380,15 +390,13 @@ def translate_myads_queries(self, args):
db_key = args.get('db_key', None)
# if db_key is DAILY_PRE or PRE then it is Daily arXiv query (#1)
if db_key == 'DAILY_PRE' or db_key == 'PRE':
arxiv_sel = args.pop('arxiv_sel', None)
if arxiv_sel and self.validate_arxiv_sel(arxiv_sel) and date_start and date_end and start_year:
# if all entries are valid include them, oring them
arxiv_class = '(' + ' OR '.join(['arxiv_class:' + c + '.*' for c in arxiv_sel.split(',')]) + ')'
arxiv_class = self.arxiv_class_addition_myads_queries(args)
if arxiv_class and date_start and date_end and start_year:
title = self.translate_title_for_myads(title_str)
# OR arxiv classes and title if db_key is DAILY_PRE,
# otherwise leave empty which is going to be AND
add_or = ' OR ' if args.get('db_key', None) == '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 = '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 Down Expand Up @@ -419,9 +427,13 @@ def translate_myads_queries(self, args):
authors_str = args.pop('author', None)
if authors_str:
authors = self.classic_field_to_array(authors_str)
weekly_citation_query = 'citations(author:{authors})'.format(authors=' '.join(authors))
# trending((keyword1 OR keyword2) bibstem:arxiv arxiv_class:astro_ph.*)
arxiv_class = self.arxiv_class_addition_myads_queries(args)
arxiv_addition = 'bibstem:arxiv %s' % arxiv_class if arxiv_class and args.get('db_key', None) == 'PRE' else None
weekly_citation_query = 'citations(author:{authors})'.format(authors=' '.join(authors)) if arxiv_addition is None else \
'citations((author:{authors}) {arxiv_addition})'.format(authors=' '.join(authors), arxiv_addition=arxiv_addition)
self.translation.search.append(urllib.quote(weekly_citation_query))
self.translation.sort = urllib.quote('score desc')
self.translation.sort = urllib.quote('entdate desc')
else:
self.translation.error_message.append('MISSING_REQUIRED_PARAMETER')

Expand All @@ -430,7 +442,10 @@ def translate_myads_queries(self, args):
title_str = args.pop('title', None)
if title_str:
title = self.translate_title_for_myads(title_str)
weekly_keyword_query = 'trending({title})'.format(title=title)
arxiv_class = self.arxiv_class_addition_myads_queries(args)
arxiv_addition = 'bibstem:arxiv %s' % arxiv_class if arxiv_class and args.get('db_key', None) == 'PRE' else None
weekly_keyword_query = 'trending({title})'.format(title=title) if arxiv_addition is None else \
'trending(({title}) {arxiv_addition})'.format(title=title, arxiv_addition=arxiv_addition)
self.translation.search.append(urllib.quote(weekly_keyword_query))
self.translation.sort = urllib.quote('score desc')
else:
Expand All @@ -441,7 +456,10 @@ def translate_myads_queries(self, args):
title_str = args.pop('title', None)
if title_str:
title = self.translate_title_for_myads(title_str)
weekly_keyword_query = 'useful({title})'.format(title=title)
arxiv_class = self.arxiv_class_addition_myads_queries(args)
arxiv_addition = 'bibstem:arxiv %s' % arxiv_class if arxiv_class and args.get('db_key', None) == 'PRE' else None
weekly_keyword_query = 'useful({title})'.format(title=title) if arxiv_addition is None else \
'useful(({title}) {arxiv_addition})'.format(title=title, arxiv_addition=arxiv_addition)
self.translation.search.append(urllib.quote(weekly_keyword_query))
self.translation.sort = urllib.quote('score desc')
else:
Expand Down

0 comments on commit 9f3eef8

Please sign in to comment.