From 926d280e4cf895953f1ae90b055ee60d717dfb6b Mon Sep 17 00:00:00 2001 From: golnazads <28757512+golnazads@users.noreply.github.com> Date: Fri, 8 Nov 2019 14:50:56 -0500 Subject: [PATCH 1/2] couple of modifications for myads: 1-first query switched the OR, 2-third query if db_key is PRE add a prefix bibstem:arxiv --- .../tests/tests_unit/test_search_redirect.py | 22 ++++++++++++---- tugboat/views.py | 26 ++++++++++--------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/tugboat/tests/tests_unit/test_search_redirect.py b/tugboat/tests/tests_unit/test_search_redirect.py index 07f1fea..9f86d6d 100644 --- a/tugboat/tests/tests_unit/test_search_redirect.py +++ b/tugboat/tests/tests_unit/test_search_redirect.py @@ -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'), @@ -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'), @@ -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 @@ -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'), @@ -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'), diff --git a/tugboat/views.py b/tugboat/views.py index f550037..ed5f1fa 100644 --- a/tugboat/views.py +++ b/tugboat/views.py @@ -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) @@ -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, @@ -381,13 +381,15 @@ 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', 'PRE') == '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)) @@ -395,9 +397,9 @@ def translate_myads_queries(self, args): 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, @@ -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: @@ -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: @@ -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: From 30af9979a2474f1eef8decb949cee1d570ef449e Mon Sep 17 00:00:00 2001 From: golnazads <28757512+golnazads@users.noreply.github.com> Date: Fri, 8 Nov 2019 14:54:39 -0500 Subject: [PATCH 2/2] default for db_key for adding prefix to third query of myads should be None --- tugboat/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tugboat/views.py b/tugboat/views.py index ed5f1fa..68b8226 100644 --- a/tugboat/views.py +++ b/tugboat/views.py @@ -386,7 +386,7 @@ 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', 'PRE') == 'PRE' else '' + 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,